Specifying Expiration Attributes
Expiration attributes govern the automatic eviction of regions and region entries from the cache. Eviction is based on the time elapsed since the last update or access to the object. This is referred to as the least-recently-used (LRU) eviction process. Expiration options range from marking the expired object as invalid to completely removing it from the distributed cache. Eviction can help keep data current by removing outdated entries, prompting a reload the next time they are requested. Eviction may also be used to recover space in the cache by clearing out unaccessed entries and regions.
Similar to application plug-ins, expiration activities are hosted by each application that defines a region in its cache.
The following example shows a declaration that causes the region’s entries to be invalidated in the local cache after they have not been accessed for one minute.
<region-attributes> <entry-idle-time> <expiration-attributes timeout="60" action="local-invalidate"/> </entry-idle-time> </region-attributes>
Region and region entry expiration attributes are set at the region level. By default, regions and entries do not expire. The following attributes cover two types of expiration: time-to-live (TTL) and idle timeout.
||Number of seconds that the region remains in the cache after the last creation or update before the expiration action occurs.|
||For entries, the counter is set to zero for
||Number of seconds that the region remains in the cache after the last access before the expiration action occurs.|
||The idle timeout counter for an object is reset when its TTL counter is reset. An entry’s idle timeout counter is also reset whenever the entry is accessed through a
The idle timeout counter for a region is reset whenever the idle timeout is reset for one of its entries.
Expiration is measured by comparing expiration attribute settings with the last accessed time and last modified time statistics. These statistics are directly available to applications through the
CacheStatistics object that is returned by the
RegionEntry::getStatistics functions. The
CacheStatistics object also provides a function for resetting the statistics counters.
You can specify one of the following actions for each expiration attribute:
- Destroy. Removes the object completely from the cache. For regions, all entries are destroyed as well. Destroy actions are distributed according to the region’s distribution settings.
- Invalidate. Marks the object as invalid. For entries, the value is set to
NULL. You invalidate a region by invalidating all its entries. Invalidate actions are distributed according to the region’s distribution settings. When an entry is invalid, a
getcauses the cache to retrieve the entry according to the steps described in Entry Retrieval.
- Local destroy. Destroys the object in the local cache but does not distribute the operation.
- Local invalidate. Invalidates the object in the local cache but does not distribute the operation. Note: Destruction and invalidation cause the same event notification activities whether carried out explicitly or through expiration activities.
Expiration activities in distributed regions can be distributed or performed only in the local cache. So one cache could control region expiration for a number of caches in the distributed system.