Hibernate二级缓存:命中和未命中计数始终为0

时间:2017-09-13 21:47:55

标签: hibernate ehcache

我使用hibernate 4.1.7和ehcache作为二级缓存

<property name="hibernate.cache.region.factory_class">
          org.hibernate.cache.ehcache.EhCacheRegionFactory</property>              
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.use_query_cache">true</property>

当我在DB调用之前和之后检查未命中计数和命中计数时,我总是得到0.

long loadEntityCount = HibernateUtil.getSessionFactory().getStatistics().getSecondLevelCacheStatistics("com.xys.Program").getElementCountInMemory();
    long hitCount = HibernateUtil.getSessionFactory().getStatistics().getSecondLevelCacheStatistics("com.xys.Program").getHitCount();
    long missCount = HibernateUtil.getSessionFactory().getStatistics().getSecondLevelCacheStatistics("com.xys.Program").getMissCount();

列出patientPrograms = getProgramsForPatient(r);

loadEntityCount = HibernateUtil.getSessionFactory().getStatistics().getSecondLevelCacheStatistics("com.xyz.Program").getElementCountInMemory();
        hitCount = HibernateUtil.getSessionFactory().getStatistics().getSecondLevelCacheStatistics("com.xyz.Program").getHitCount();
        missCount = HibernateUtil.getSessionFactory().getStatistics().getSecondLevelCacheStatistics("com.xyz.Program").getMissCount();

我预计两种情况都会出现非零值,并且未命中计数会增加。

任何帮助?

0 个答案:

没有答案
相关问题