ehcache does not remove Element from memory on eviction

試著忘記壹切 提交于 2020-01-01 04:45:10

问题


  1. ehcache 2.5
  2. timeToIdleSeconds="1800" (30 minutes), so I expect element to evict after 30 minute of being idle
  3. 30 minutes after last Element usage I still can see that cache is full of elements
  4. Forcing GC and taking heap dump shows, that elements are still in the memory
  5. getSize() returns positive number and getKeys() returns keys as expected (getKeys() does not check elements expiry)
  6. getting particular element, though results in NULL value, meaning that it was expired.
  7. getKeysWithExpiryCheck() shows, that cache is empty and all element exired and evicted
  8. Forcing GC and taking heap dump shows, that elements collected out of memory.

    maxEntriesLocalHeap="10000"
    eternal="false"
    statistics="true"
    overflowToDisk="false"
    timeToIdleSeconds="1800"
    memoryStoreEvictionPolicy="LFU"
    transactionalMode="off"
    

From above I see, that ehcache make impression, that elements are expired which may lead my code logic to refresh them but under the hood memory is till polluted with elements until I call particular element or getKeysWithExpiryCheck() , which does not let me use ehcache as effective memory manger

How to make element to be GS after timeToIdleSeconds time? I want memory to be cleaned if elements aren’t used above timeToIdleSeconds.

Michael


回答1:


Ehcache will only evict elements when putting elements and your cache is above threshold. Otherwise, accessing those expired elements will result in them being expired (and removed from the Cache). There is no thread that collects and removes expired elements from the Cache in the background. Even though I wouldn't recommend it, as this will affect the Cache's performance (but if memory usage is more important, this might be a fair tradeoff), you can have a background thread doing the getKeysWithExpiryCheck() on a regular interval.

Also if memory consumption is a major point, you might want to look into the new Ehcache 2.5, which lets you (even at the CacheManager level) specify up to how much heap should be used...



来源:https://stackoverflow.com/questions/8838039/ehcache-does-not-remove-element-from-memory-on-eviction

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!