When an instance expires, it is only invalidated in the cache. It is not removed from the cache, but when next accessed it will be refreshed from the database as part of the query that was used to access it.

When an instance expires, it is only invalidated in the cache. It is not removed from the cache, but when next accessed it will be refreshed from the database as part of the query that was used to access it.

−

The application can also explicitly invalidate objects in the cache using the JPA <tt>Cache</tt> API, or the EclipseLink <tt>JpaCache</tt> API (see [[#EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Cache API|Cache API]]).

+

The application can also explicitly invalidate objects in the cache using the JPA <tt>Cache</tt> API, or the EclipseLink <tt>JpaCache</tt> API (see [[EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Cache API|Cache API]]).

−

Expiry can also be used in the query results cache (see [[EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Query Results Cache|Query Results Cache]]).

+

Expiry can also be used in the query results cache (see [[EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Query Cache|Query Results Cache]]).

−

Invalidation can also be used in a cluster through cache coordination (see [[EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Coordination|Cache Coordination]]), or from database events using database event notification (see [[EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Database Events Notification|Database Events Notification]]).

+

Invalidation can also be used in a cluster through cache coordination (see [[EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Coordination|Clustering and Cache Coordination]]), or from database events using database event notification (see [[EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/DatabaseEvents|Database Event Notification and Oracle DCN/QCN]]).

EclipseLink's cache expiry and invalidation support is provided through the <tt>CacheInvalidationPolicy</tt> class and its subclasses. The EclipseLink API offers a few advanced features that are not available through annotations or XML. It is also possible to define your own expiry or invalidation policy by defining your own <tt>CacheInvalidationPolicy</tt>. Advanced configuration can be done through using a <tt>DescriptorCustomizer</tt> to customize your entity's <tt>ClassDescriptor</tt>.

EclipseLink's cache expiry and invalidation support is provided through the <tt>CacheInvalidationPolicy</tt> class and its subclasses. The EclipseLink API offers a few advanced features that are not available through annotations or XML. It is also possible to define your own expiry or invalidation policy by defining your own <tt>CacheInvalidationPolicy</tt>. Advanced configuration can be done through using a <tt>DescriptorCustomizer</tt> to customize your entity's <tt>ClassDescriptor</tt>.

−

Advanced options:

+

<tt>CacheInvalidationPolicy</tt> advanced options:

* <tt>isInvalidationRandomized</tt> - This allows the invalidation time to be randomized by 10% to avoid a large number of instances becoming invalid at the same time and causing a bottleneck in the database load. This is not used by default.

* <tt>isInvalidationRandomized</tt> - This allows the invalidation time to be randomized by 10% to avoid a large number of instances becoming invalid at the same time and causing a bottleneck in the database load. This is not used by default.

* <tt>shouldRefreshInvalidObjectsOnClone</tt> - This ensures that an invalid object accessed through a relationship from another object will be refresh in the persistence context. This is enabled by default.

* <tt>shouldRefreshInvalidObjectsOnClone</tt> - This ensures that an invalid object accessed through a relationship from another object will be refresh in the persistence context. This is enabled by default.

Cache Expiration and Invalidation

By default, entities remain in the shared cache until they are explicitly deleted or garbage collected.

You can configure any entity with a expiry that lets you specify, either the number of milliseconds after which an entity instance should expire from the cache, or a time of day that all instances of the entity class should expire from the cache. Expiry is set on the @Cache annotation or <cache> XML element, and can be configured in two ways:

expiry - The number of milliseconds to expiry an entity instance in the cache after it has been read.

expiryTimeOfDay - The @TimeOfDay represent the 24h time of day to expiry all instances of the entity class in the cache.

When an instance expires, it is only invalidated in the cache. It is not removed from the cache, but when next accessed it will be refreshed from the database as part of the query that was used to access it.

The application can also explicitly invalidate objects in the cache using the JPA Cache API, or the EclipseLink JpaCache API (see Cache API).

Advanced Cache Invalidation

EclipseLink's cache expiry and invalidation support is provided through the CacheInvalidationPolicy class and its subclasses. The EclipseLink API offers a few advanced features that are not available through annotations or XML. It is also possible to define your own expiry or invalidation policy by defining your own CacheInvalidationPolicy. Advanced configuration can be done through using a DescriptorCustomizer to customize your entity's ClassDescriptor.

CacheInvalidationPolicy advanced options:

isInvalidationRandomized - This allows the invalidation time to be randomized by 10% to avoid a large number of instances becoming invalid at the same time and causing a bottleneck in the database load. This is not used by default.

shouldRefreshInvalidObjectsOnClone - This ensures that an invalid object accessed through a relationship from another object will be refresh in the persistence context. This is enabled by default.

shouldUpdateReadTimeOnUpdate - This updates an objects read time when the object is successfully updated. This is not enabled by default.