ExpirePolicy

In JCache, javax.cache.expiry.ExpirePolicy implementations are used to automatically expire cache entries based on different rules.

Expiry timeouts are defined using javax.cache.expiry.Duration, which is a pair of java.util.concurrent.TimeUnit, which describes a time unit and a long, defining the timeout value. The minimum allowed TimeUnit is TimeUnit.MILLISECONDS. The long value durationAmount must be equal or greater than zero. A value of zero (or Duration.ZERO) indicates that the cache entry expires immediately.

By default, JCache delivers a set of predefined expiry strategies in the standard API.

  • AccessedExpiryPolicy: Expires after a given set of time measured from creation of the cache entry, the expiry timeout is updated on accessing the key.
  • CreatedExpiryPolicy: Expires after a given set of time measured from creation of the cache entry, the expiry timeout is never updated.
  • EternalExpiryPolicy: Never expires, this is the default behavior, similar to ExpiryPolicy to be set to null.
  • ModifiedExpiryPolicy: Expires after a given set of time measured from creation of the cache entry, the expiry timeout is updated on updating the key.
  • TouchedExpiryPolicy: Expires after a given set of time measured from creation of the cache entry, the expiry timeout is updated on accessing or updating the key.

Because EternalExpirePolicy does not expire cache entries, it is still possible to evict values from memory if an underlying CacheLoader is defined.