Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Cache API"

(EclipseLink JpaCache API example)
 
Line 60: Line 60:
 
{{EclipseLink_JPA
 
{{EclipseLink_JPA
 
|previous= [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching/Query Options|Query Cache Options and In-memory Querying]]
 
|previous= [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching/Query Options|Query Cache Options and In-memory Querying]]
|next=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching/Query Options|Query Cache Options and In-memory Querying]]
+
|next=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching/Interceptors|Cache Interceptors and External Caches]]
 
|up=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching|Caching]]
 
|up=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching|Caching]]
 
|version=2.4 DRAFT}}
 
|version=2.4 DRAFT}}

Latest revision as of 14:46, 30 May 2012

EclipseLink JPA

link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source

Elug api package icon.png Key API

Elug api package icon.png Native API

Cache API

The cache can be accessed directly at runtime using the JPA Cache API, or the EclipseLink JpaCache API. The cache API can be used to evict or invalidate objects in the cache, and access the cache directly. These APIs can be used from application services, to invalidate the cache when the application knows that some data has changed, such as the application using direct JDBC, or other application accessing the database, or database event services.

The EclipseLink native API IdentityMapAccessor can also be used to directly access the cache of an EclipseLink Session.

The JPA Cache API includes:

  • contains(Class, Object) - Return if the Id is contained in the cache for the class.
  • evict(Class, Object) - Invalidate the object in the cache for the Id and class.
  • evict(Class) - Invalidate all instances of the class in the cache.
  • evictAll() - Invalidate the entire cache.

The EclipseLink JpaCache API includes:

  • clear() - Clears everything from the cache. This should only be used when no other threads are accessing the cache, such as testing.
  • clear(Class) - Clear the cache for a class. This should only be used if no other cached instances reference the class.
  • clearQueryCache() - Clears everything from the query cache.
  • clearQueryCache(String) - Clears the query cache for a specific named query.
  • timeToLive(Object) - Returns the number of milliseconds until a cached object becomes invalid.
  • isValid(Object) - Checks if the cached object is valid.
  • isValid(Class cls, Object) - Checks if the cached object for the class and Id is valid.
  • print() - Dumps the contents of the cache to the EclipseLink log. This is for debugging purposes.
  • print(Class) - Dumps the contents of the cache for the class to the EclipseLink log. This is for debugging purposes.
  • printLocks() - Dumps the current cache locks to the EclipseLink log. This is for debugging cache deadlocks.
  • validate() - Checks that there are no dangling references from cache objects to un-cached objects.
  • getObject(Class, Object) - Returns the cached object for the class and Id.
  • putObject(Object) - Put the object into the cache.
  • removeObject(Object) - Remove the object from the cache. This should only be used if no other cached instances reference the object.
  • removeObject(Class, Object) - Remove the object with the class and Id from the cache. This should only be used if no other cached instances reference the object.
  • contains(Object) - Return if the object is contained in the cache.
  • evict(Object) - Invalidate the object from the cache.
  • evict(Object, boolean) - Invalidate the object from the cache and broadcast the invalidation in the EclipseLink cache coordination cluster.
  • evict(Object, boolean) - Invalidate the object from the cache and broadcast the invalidation in the EclipseLink cache coordination cluster.
  • evict(Class, Object, boolean) - Invalidate the object with the class and Id from the cache and broadcast the invalidation in the EclipseLink cache coordination cluster.
  • getId(Object) - Return the object's JPA Id.
JPA Cache API example
emf.getCache().evictAll();
EclipseLink JpaCache API example
((JpaCache)emf.getCache()).clear();

Eclipselink-logo.gif
Version: 2.4 DRAFT
Other versions...