I am planning on using a SelfPopulatingCache in my application component, as it supports read-through and what seems like a backing cache for refreshes.
However, I am a little bemused by the timeToLiveSeconds configuration. This is my test configuration:
<ehcache>
<diskStore path="java.io.tmpdir"/>
<cache name="myCache" maxElementsInMemory="50000" overflowToDisk="false"
eternal="false" timeToIdleSeconds="0" timeToLiveSeconds="2"/>
</ehcache>
In my unit tests, I perform the following:
- Verify there are 2 entries in my cache
- Sleep for 3 seconds
- However, after the sleep there are still 2 entries in my cache.
Per other posts online (and not the documentation), when I next perform a read, my entries should be evicted.
However, instead the CacheEntryFactory will be invoked, and a null Element will be added to the cache for my expired elements.
Is there any way to configure this to instead perform a full eviction when timeToLiveSeconds expires?
I believe “full eviction” can only happen if there was a separate expiry thread. Unfortunately, for in-memory entries there’s no such thing. Quoting Ehcache FAQ: