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 ]
According to what I have read in the documents this event should spool the element to disk, however when I'm trying afterward to read this item from the cache I'm getting back null.
What am I missing here in my configuration in order to be able to use the cache when my cache heap memory is full?