-
1. How to get CacheManager Instance in Hibernate
galder.zamarreno Feb 4, 2011 10:37 AM (in response to glsgolden)Assuming that you're using EHCache for 2nd level caching, Hibernate does not provide an standard way to get hold of the underlying cache provider, and so you cannot get hold of the Infinispan CacheManager. I can assure you (I wrote the Infinispan 2LC code ) that a only a single cache manager is used for maintaining the Hibernate 2LC.
-
2. How to get CacheManager Instance in Hibernate
glsgolden Feb 8, 2011 1:10 AM (in response to galder.zamarreno)thanks
-
3. Re: How to get CacheManager Instance in Hibernate
mjhaller May 26, 2016 4:57 PM (in response to galder.zamarreno)Is this still true? I see in other posts one isn't supposed to fiddle with the CacheManager, but I see valid use cases for getting information about individual cached ids.
When determining the health of the 2LC for testing purposes, it is useful to be able to look at individual cache entries. For example, I was looping through the cache.getKeys() with EhCache:
CacheKey cacheKey = (CacheKey) key;
Element element = cache.getQuiet(key);
// fields like this are useful to print for debugging
cacheKey.getKey().toString()
element.getHitCount();
element.getLastAccessTime();
element.getLastUpdateTime();
element.getCreationTime();
-
4. Re: How to get CacheManager Instance in Hibernate
mjhaller May 27, 2016 12:21 AM (in response to mjhaller)Nevermind. All this is available from the hibernate l2 stats:
Statistics statistics = entityManager.getSession().getSessionFactory().getStatistics();
statistics.setStatisticsEnabled(true);
SecondLevelCacheStatistics l2cacheStats = statistics.getSecondLevelCacheStatistics(cacheName);