Ehcache eternal cache forget items
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?
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.
<sql-query name="queryname">
<synchronize table="tablename"/>
...
</sql-query>
精彩评论