【发布时间】:2016-12-27 13:44:30
【问题描述】:
我是在我的项目中实现缓存技术的新手,在阅读了一些博客之后,我决定使用 Ehcache。现在我在确定如何检查缓存中过期条目的正确方法方面遇到了一些问题,以便我可以同步/异步刷新我的缓存。
Ehcache 配置文档说
timeToLiveSeconds – 一个元素可以在缓存中存在的最大秒数,无论使用如何。 元素在此时过期 限制并且将不再从缓存中返回。
下面是我的缓存配置
<cache name="userCache"
maxEntriesLocalHeap="500"
eternal="false"
timeToIdleSeconds="30"
timeToLiveSeconds="30"
memoryStoreEvictionPolicy="LRU"
transactionalMode="off">
<persistence strategy="none" />
</cache>
我假设该条目即使在过期后仍保留在缓存中。我想做如下的事情:
get an element from the cache
if not expired, return the element
if expired, return the stale entry and reload the cache asynchronously.
但似乎 Ehcache 会自行删除过期的缓存条目,因此我在实现上述算法时面临挑战。是否有任何配置可以设置为即使在过期后也不从缓存中删除?
【问题讨论】: