Java – ehcache does not delete elements from memory during eviction
> ehcache 2.5
maxEntriesLocalHeap="10000" eternal="false" statistics="true" overflowToDisk="false" timeToIdleSeconds="1800" memoryStoreEvictionPolicy="LFU" transactionalMode="off"
From the above, I can see that this ehcache is impressive. Those elements have expired, which may cause my code logic to refresh, but it is in the engine memory until it is polluted by elements, until I call a specific element or getkeyswithexpirycheck (), which does not allow me to use ehcache as an effective memory manager
How to make an element the timetoidleseconds time after GS? If the element is not used more than timetoidleseconds, I want to clean up memory
Michael
Solution
Ehcache will evict elements only when they are placed and the cache is above the threshold Otherwise, accessing those expired elements will cause them to expire (and delete them from the cache) No thread collects and deletes expired elements from the cache in the background Even if I don't recommend it, because it will affect the performance of the cache (but this may be a fair trade-off if memory usage is more important), you can have a background thread execute getkeyswithexpirycheck() within a certain time interval
In addition, if memory consumption is an important point, you may need to check the new ehcache 2.5. You can specify how many heaps to use even at the CacheManager level