I'm trying to configure Ehcache (version 2.5) such that it never forgets items. I'm configuring programmatically and I haven't touched any of the configuration XML files. By setting eternal
to true
it is my understanding that the only circumstances under which an item could be removed from the cache would be if I run out of disk space or exceed maxBytesLocalDisk
(or if the application terminates). However, this test program does not show that behavior:
public static void main(String[] args) {
CacheManager cacheManager = CacheManager.create();
Cache cache = new Cache(
new CacheConfiguration().name("test")
.overflowToDisk(true)
.eternal(true)
.maxBytesLocalHeap(1, MemoryUnit.MEGABYTES)
.overflowToOffHeap(false)
.maxBytesLocalDisk(100, MemoryUnit.GIGABYTES)
.maxElementsOnDisk(0)
.timeToIdleSeconds(0)
.timeToLiveSeconds(0)
.diskStorePath("E:\\Data\\Ehcache"));
cacheManager.addCache(cache);
for(int i = 0; i < 1000000; i++){
cache.put(new Element("key_" + i, "value_" + i));
}
System.out.println(cache.getSize());
}
So after adding 1 million elements to my cache, which I told to overflow to a disk that is large enough by orders of magnitude, I only end up with 3276 items at the end. What is happening here?