I have started using ehcache for caching purpose
I would like a cache that will use the disk in case it does not have enough memory space.
I have wrote this code:
CacheManager manager = CacheManager.getInstance();
CacheConfiguration config = new CacheConfiguration()
.name("mycache")
.maxBytesLocalHeap(5,MemoryUnit.MEGABYTES)
.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU) //least frequntly used
.eternal(false) //should expire
.timeToLiveSeconds(43200)//12 hours
.timeToIdleSeconds(0)
.diskExpiryThreadIntervalSeconds(300)
.maxEntriesLocalDisk(0)//unlimited
.persistence(new PersistenceConfiguration().strategy(Strategy.LOCALTEMPSWAP));
cache = new Cache(config);
CacheWrapperEventListener listener = new CacheWrapperEventListener(name);
cache.getCacheEventNotificationService().registerListener(listener);
manager.addCache(cache);
Now i'm starting to add items to cache, at certain time ( I guess after reaching the memory limit size) i'm getting in my listener notifyElementEvicted event
*notifyElementEvicted [ name = mycache status = STATUS_ALIVE eternal = false overflowToDisk = true maxEntriesLocalHeap = 0 maxEntriesLocalDisk = 0 memoryStoreEvictionPolicy = LFU timeToLiveSeconds = 43200 timeToIdleSeconds = 0 persistence = LOCALTEMPSWAP diskExpiryThreadIntervalSeconds = 300 cacheEventListeners: com.jobsin.server.infra.cache.CacheWrapperEventListener ; orderedCacheEventListeners: maxBytesLocalHeap = 5242880 overflowToOffHeap = false maxBytesLocalOffHeap = 0 maxBytesLocalDisk = 0 pinned = false ]
I see the data is saved to disk since in the statistics i get getLocalDiskSizeInBytes() > 0 . The question is why after some element is being evicted from heap memory (and now should only on disk) i cannot get it any more and get from cache is null. Also strange i'm not getting any notifyElementRemoved event on this item
What am i missing here in my configuration in order to be able to use the cache when my cache heap memory is full?