Each cache entry contains information about:
- Last used
- Max idle
- Expiration time
Where Expiry Time = Max Idle + Last Used
Use this information to get the lifetime of each cache entry.
The CacheEntry.getLifeSpan() method does not work as expected, which returns the lifetime of this record. It returns -1, which means unlimited lifetime.
Here is a sample code:
import org.infinispan.Cache; import org.infinispan.configuration.cache.CacheMode; import org.infinispan.configuration.cache.ConfigurationBuilder; import org.infinispan.container.entries.CacheEntry; import org.infinispan.container.entries.TransientCacheEntry; import org.infinispan.manager.DefaultCacheManager; import org.infinispan.manager.EmbeddedCacheManager; public class InfinispanTTL { public static void main(String[] args) throws InterruptedException { System.out.println("start"); ConfigurationBuilder confBuilder = new ConfigurationBuilder();
Output:
Strategy used by container=NONE Lifespan of container=5000 Expiry Time = Max Idle + Last Used Max Idle=1000 Last Used=2000 Expiry Time=3000 Life span from session cache=-1 Expiry Time from session cache=3000 Old value=1 Set value New value=3 Expiry Time from session cache=3000
Braj
source share