I am trying to configure Ehcache (version 2.5) so that it never forgets the elements. I am programming programmatically and I have not touched any XML configuration files. By setting eternal
to true
, I understand that the only circumstances that can cause an item to be removed from the cache will be if I run out of disk space or exceed maxBytesLocalDisk
(or if the application terminates). However, this test program does not show this 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, as I said, is full on a disk that is quite large by orders of magnitude, I only end up with 3276 points at the end. What's going on here?
Michael mcgowan
source share