I am using Hibernate 4.1.7 and EhCache as second level cache. I am implementing a rest service to clear cahce (evict all regions ) as needed.
Below is code snippet
org.hibernate.stat.Statistics statistics = HibernateUtil.getSessionFactory().getStatistics();
statistics.setStatisticsEnabled(true);
long hits = statistics.getSecondLevelCacheHitCount();
long misses = statistics.getSecondLevelCacheMissCount();
long puts = statistics.getSecondLevelCachePutCount();
logger.info("Hits: " + hits + " Misses: " + misses + " Puts:" + puts);
cache.evictEntityRegions();
hits = statistics.getSecondLevelCacheHitCount();
misses = statistics.getSecondLevelCacheMissCount();
puts = statistics.getSecondLevelCachePutCount();
logger.info("Hits: " + hits + " Misses: " + misses + " Puts:" + puts);
long hit0 = statistics.getQueryCacheHitCount();
long miss0 = statistics.getSecondLevelCacheMissCount();
Unfortunately, I get same values for hits/misses and puts after I evict all regions.
Appreciated if some can shed some lights.