Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Cache API

EclipseLink JPA

Eclipselink-logo.gif
EclipseLink
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug 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...

Copyright © Eclipse Foundation, Inc. All Rights Reserved.