My current config is as below, I intended to only cache up to 30 elements and evict the oldest one when the number is more than 30:
<ehcache>
<diskStore path="/path/to/store/"></diskStore>
<cache name="myCache"
eternal="false"
maxEntriesLocalHeap="30"
maxEntriesLocalDisk="30"
memoryStoreEvictionPolicy="FIFO">
<persistence strategy="localTempSwap"/>
</cache>
</ehcache>
I have another scheduled job which runs every minute to put a new element into the cache. So I expect to get only 30 elements within recent 30 minutes. But the expiring/eviction was not as expected. Some very old elements were still kept while some elements within recent 30 minutes were unexpectedly evicted. Is there anything I missed here?
I've read through the expiring/eviction related documentation in ehcache, but did not find any clue. Hope someone can help :)
BTW, the ehcache version is 2.6.6
Thanks @Louis for the answer and suggestion.
In ehcache doc, I learned that
memoryStoreEvictionPolicy
is only for memory store, while in my case disk store is used. And also eviction policy for disk store is by default LFU and not configurable.So to achieve what I am expecting, I changed to use memory store only, given that the current persistent strategy for disk store is not restartable (localTempswap), which is equivalent in using memory store. The final config is as: