ehcache removes element from cache following eviction event

104 views
Skip to first unread message

Ofer Cohen

unread,
Oct 29, 2014, 4:33:57 PM10/29/14
to ehcach...@googlegroups.com
  1. What version of Ehcache you are currently using; - 2.9
  2. Paste the configuration for the Cache/CacheManager you have an issue with;
  3. Add any name and version of other library or framework you use Ehcache with (e.g. Hibernate); - Tomcat 7
  4. Providing JDK and OS versions maybe useful as well. JDK 7 + WIndows 8

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?

Reply all
Reply to author
Forward
0 new messages