|Getting Started with Pivotal GemFire / QuickStart Examples|
Expiration helps you ensure that your data is current and pertinent by removing old and unused entries from the cache.
It can also give you some control over cache size. When you try to access an expired entry, the value is not there and your cache looks to another source for a fresh update. Usually it calls the loader you have installed on the data region.
You can expire entries based on how recently they were added or updated, or based on how recently they were accessed by your application, added, or updated. Add/update-based expiration, called time-to-live or TTL, keeps your application from accessing stale data. Add/update/access-based, or idle-time, expiration keeps your application from accessing stale data and from using memory for data it isn't interested in accessing.
This example uses idle time expiration, configured through the XML file to destroy expired entries. The program creates three entries and then waits beyond the expiration time. During the wait time, the program updates one entry and accesses another. When the expiration time elapses, only the third, unaccessed and unmodified entry is expired. The cache listener, installed on the region, reports on all changes to the entries.
In a single session, run the example:
$ java quickstart.DataExpiration
Program and cache configuration source files for the example, including the listener declared in DataExpiration.xml:
|DataExpiration.xml||Configures a region with entry idle time expiration.|
|DataExpiration.java||Adds data to the cache and lists entries before and after expiration.|
|SimpleCacheListener.java||A CacheListener that reports cache events.|