gpt4 book ai didi

java - Hibernate & EhCache : net. sf.ehcache.Statistics 未填充?

转载 作者:行者123 更新时间:2023-11-29 09:24:37 25 4
gpt4 key购买 nike

我认为我的 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"/>

最佳答案

确实很奇怪,这些调试语句确实意味着您正在访问 ersistence.unit:unitName=#pu-pay.c.u.p.model.Action 缓存……我想知道您的 CacheManager 是否正确,它会不会是 Hibernate Provider正在使用另一个实例?

您的 hibernate 配置是什么样的?

关于java - Hibernate & EhCache : net. sf.ehcache.Statistics 未填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3661580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com