Forcing GC and taking heap dump shows, that elements collected out of memory.
maxEntriesLocalHeap="10000"
eternal="false"
statistics="true"
overflowToDisk="false"
timeToIdleSeconds="1800"
memoryStoreEvictionPolicy="LFU"
transactionalMode="off"
From above I see, that ehcache make impression, that elements are expired which may lead my code logic to refresh them but under the hood memory is till polluted with elements until I call particular element or getKeysWithExpiryCheck() , which does not let me use ehcache as effective memory manger
How to make element to be GS after timeToIdleSeconds time? I want memory to be cleaned if elements aren’t used above timeToIdleSeconds.
Michael
Ehcache will only evict elements when putting elements and your cache is above threshold. Otherwise, accessing those expired elements will result in them being expired (and removed from the Cache). There is no thread that collects and removes expired elements from the Cache in the background. Even though I wouldn't recommend it, as this will affect the Cache's performance (but if memory usage is more important, this might be a fair tradeoff), you can have a background thread doing the getKeysWithExpiryCheck() on a regular interval.
Also if memory consumption is a major point, you might want to look into the new Ehcache 2.5, which lets you (even at the CacheManager level) specify up to how much heap should be used...