Need a help here. I am working on a project where I have to delete elements(keys) when it is not used for a certain time. I tried with both timeToLiveSeconds and timeToIdleSeconds as 60 seconds. Also tried with only timeToLiveSeconds=60 and with only timeToIdleSeconds=60. But I still see that element in cache.
fyi: I have some code to show all cached elements on the screen.
Screenshot 0: Before calling REST service for my action. Expectation: the element Should NOT appear in the Cache Web page – Working as expected
Screenshot 1: After calling REST service to execute my action. Expectation: See the element in the Cache list in the web page – Working as expected
Now Idle for 60 seconds (do not call the REST service, means the element is not used for 60 seconds)
Screenshot 2: Refresh the Cache Web page. Expectation: the element Should NOT appear in the Cache Web page – NOT working as expected
- element means AF2TDU2001
- We are using ehcache 2.5.2
Here is is my code:
/**
*
* @param cacheName
* @param diskPersistent
*/
private static void addCache(String cacheName, boolean diskPersistent) {
/*
@param name - the name of the cache. Note that "default" is a reserved name for the defaultCache.
@param maxElementsInMemory - the maximum number of elements in memory, before they are evicted (0 == no limit)
@param memoryStoreEvictionPolicy - one of LRU, LFU and FIFO. Optionally null, in which case it will be set to LRU.
@param overflowToDisk - whether to use the disk store
@param diskStorePath - this parameter is ignored. CacheManager sets it using setter injection.
@param eternal - whether the elements in the cache are eternal, i.e. never expire
@param timeToLiveSeconds - the default amount of time to live for an element from its creation date
@param timeToIdleSeconds - the default amount of time to live for an element from its last accessed or modified date
@param diskPersistent - whether to persist the cache to disk between JVM restarts
@param diskExpiryThreadIntervalSeconds - how often to run the disk store expiry thread. A large number of 120 seconds plus is @param recommended
@param registeredEventListeners - a notification service. Optionally null, in which case a new one with no registered listeners will @param be created.
@param bootstrapCacheLoader - the BootstrapCacheLoader to use to populate the cache when it is first initialised. Null if none is @param required.
@param maxElementsOnDisk - the maximum number of Elements to allow on the disk. 0 means unlimited.
@param diskSpoolBufferSizeMB - the amount of memory to allocate the write buffer for puts to the DiskStore.
*/
Cache cache = new Cache(cacheName,
10000, // maxElementsInMemory
MemoryStoreEvictionPolicy.LRU, // memoryStoreEvictionPolicy
false, // overflowToDisk
diskStorePath,
true, // eternal
60, // timeToLiveSeconds
60, // timeToIdleSeconds
false, // diskPersistent
1, // diskExpiryThreadIntervalSeconds
null,
null,
0, // bootstrapCacheLoader
0, // maxElementsOnDisk
false);
cacheManager.addCache(cache);
}