在驱逐时,ehcache不会从内存中删除Element [英] ehcache does not remove Element from memory on eviction

查看:697
本文介绍了在驱逐时,ehcache不会从内存中删除Element的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. ehcache 2.5

  2. timeToIdleSeconds =1800(30分钟),所以我希望元素在闲置30分钟后逐出

  3. 最后一次使用Element后30分钟我仍然可以看到缓存中充满了元素

  4. 强制GC并进行堆转储显示,这些元素仍在内存中

  5. getSize()返回正数,getKeys()按预期返回键(getKeys()不检查元素到期)

  6. 获取特定元素,尽管结果在NULL值中,意味着它已过期。

  7. getKeysWithExpiryCheck()显示,该缓存为空,所有元素都已被放逐并被驱逐

  8. 强制GC并进行堆转储显示,这些元素从内存中收集。

  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"


从上面我看到,ehcache给人的印象是,元素已过期,这可能导致我的代码逻辑刷新它们但引擎盖内存是直到我调用特定元素或getKeysWithExpiryCheck(),这不允许我使用ehcache作为有效的内存管理器

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

如何在timeToIdleSeconds时间之后使元素成为GS ?如果在timeToIdleSeconds之上没有使用元素,我希望清理内存。

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

Michael

推荐答案

Ehcache只会在放置元素并且缓存高于阈值时逐出元素。否则,访问这些过期的元素将导致它们过期(并从缓存中删除)。没有线程在后台从Cache中收集和删除过期的元素。即使我不推荐它,因为这会影响Cache的性能(但如果内存使用更重要,这可能是一个公平的权衡),你可以让一个后台线程定期执行getKeysWithExpiryCheck()。

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.

此外,如果内存消耗是主要问题,您可能需要查看新的Ehcache 2.5,它可以让您(甚至在CacheManager级别)指定多少应该使用堆...

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...

这篇关于在驱逐时,ehcache不会从内存中删除Element的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆