【发布时间】:2011-04-09 08:41:06
【问题描述】:
我认为我的 Hibernate (3.5.3) 二级缓存已经很好地配置了 EhCache (2.2)。
至少,我观察到以下日志条目:
20:15:28 DEBUG [net.sf.ehcache.Cache#searchInStoreWithStats] persistence.unit:unitName=#pu-pay.c.u.p.model.ActionCache: persistence.unit:unitName=#pu-pay.c.u.p.model.Action store hit for c.u.p.model.Action#TRT
20:15:28 DEBUG [net.sf.ehcache.Cache#searchInStoreWithStats] persistence.unit:unitName=#pu-pay.c.u.p.model.ActionCache: persistence.unit:unitName=#pu-pay.c.u.p.model.Action store hit for c.u.p.model.Action#PID
(...这些“存储命中”真的表明缓存正在工作吗?)
现在让我困惑的是:
当我按如下方式检查统计数据时:
cacheManager.getCache("persistence.unit:unitName=#pu-pay.c.u.p.model.Action").getStatistics().toString()
...我看到的只是:
name = persistence.unit:unitName=#pu-pay.c.u.p.model.Action cacheHits = 0 onDiskHits = 0 inMemoryHits = 0 misses = 0 size = 0 averageGetTime = 0.0 evictionCount = 0
...没有命中,没有未命中,...没有...
在ehcache.xml,我有:
<defaultCache
...
statistics="true"
...
/>
<cache
name="persistence.unit:unitName=#pu-pay.c.u.p.model.Action"
maxElementsInMemory="100"
eternal="true"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="false"
statistics="true"
/>
这会给任何人敲响警钟吗?我是否也必须在其他位置启用统计信息? ...
更新:
persistence.xml 指定:
<property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.EhCacheRegionFactory"/>
<property name="hibernate.cache.use_query_cache" value="false"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.generate_statistics" value="true"/>
【问题讨论】:
标签: java hibernate jpa jakarta-ee ehcache