开发者

Hibernate & EhCache: net.sf.ehcache.Statistics not populated?

开发者 https://www.devze.com 2023-01-15 18:19 出处:网络
I think my Hibernate (3.5.3) Second Level Cache is well configured with EhCache (2.2). At least, I observe following log entries:

I think my Hibernate (3.5.3) Second Level Cache is well configured with EhCache (2.2).

At least, I observe following log entries:

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

(... do these "store hits" really indicate that the cache is working?)

What puzzles me now is:

When I inspect the statistics as follows:

cacheManager.getCache("persistence.unit:unitName=#pu-pay.c.u.p.model.Action").getStatistics().toString()

... all I see is:

 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

... no hits, no misses,... nothing...

In ehcache.xml, I have:

   <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"
        />

Does this ring a bell to any body? Do I have to enable statistics in another location as well? ...


Upd开发者_如何学运维ate:

persistence.xml specifies:

        <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"/>


Weird indeed, these debug statement do mean you are having hits to the ersistence.unit:unitName=#pu-pay.c.u.p.model.Action Cache… I wonder whether your CacheManager is the right one, could it be the Hibernate Provider is using another instance ?

How does your hibernate config look like ?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号