ehcache永久缓存忘记项
Env:Spring 2.5.6、Hibernate 3.3.2、Ehcache 2.0.1、terracotta 3.2.1
我在抽象类上有一个缓存(有 5 个继承者),
<cache name="com.f4.owl.domain.good.GoodType"
maxElementsInMemory="15000"
eternal="false"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false">
<terracotta/>
</cache>
我还有一个加载 6550 个元素的页面。起初,缓存似乎正在工作(从缓存中检索项目并且页面加载速度更快),但过了一段时间(从几分钟到几个小时),它会从数据库重新加载所有内容。
使用 terracotta 开发者控制台,看起来缓存确实从 6550 个元素清空到大约 70 个元素。
据我了解,将 timeToIdleSeconds 和 timeToLiveSeconds 设置为零应该使缓存永恒,因此它永远不会收缩。有人可以解释一下吗?
Env: Spring 2.5.6, Hibernate 3.3.2, Ehcache 2.0.1, terracotta 3.2.1
I have a cache on an abstract class (with 5 inheritors)
<cache name="com.f4.owl.domain.good.GoodType"
maxElementsInMemory="15000"
eternal="false"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false">
<terracotta/>
</cache>
I also have a page which loads 6550 elements. at first the cache seems to be working (items are retrieved from the cache and the page loads a lot faster) but after a while (going from a couple of minutes to some hours), it reloads everything from the database.
using terracotta developer console, it really seems like the cache is emptying from 6550 to about 70 elements.
from what I understand, setting both timeToIdleSeconds and timeToLiveSeconds to zero should make the cache eternal and so it should never shrink. Can someone shed some light on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于成功了。
它是由没有显式同步表的sql查询(在完全不相关的表上)引起的,从而导致整个缓存被清空。
这里的解释: http://opensource.atlassian.com/projects/hibernate/browse /HHH-2224
解决方案是为任何映射文件中定义的所有非只读 sql 查询设置同步表。
finally nailed it.
it was caused by a sql query (on a completely unrelated table) without explicit synchronized table, hence causing the full cache to be emptied.
explanations here : http://opensource.atlassian.com/projects/hibernate/browse/HHH-2224
the solution is to set synchronize table for all non readonly sql-queries defined in any mapping file.