• Bug
  • Status: Closed
  • 0 Showstopper
  • Resolution: Fixed
  • ehcache-core
  • asingh
  • Reporter: kdombeck
  • September 21, 2009
  • 0
  • Watchers: 0
  • July 27, 2012
  • September 26, 2009



I am currently using ehcache 1.5 with Hibernate and upgraded to 1.6.2 but now I am getting invalid cache statistics for memoryStoreHitCount, diskStoreHitCount, missCountNotFound, etc. I do not have any specific caches configured in ehcache.xml other than the defaultCache. What I found was that Hibernate is creating the caches via CacheManger.addCache(String cacheName). This method calls clone() on the default cache. Since the statistics counters are now AtomicLong instead of just long they are not being cloned. I am guessing that this was introduced when they were converted from longs to AtomicLongs http://sourceforge.net/tracker/ViewIssue.jspa?key=2831182 (EHC-36)

Here is a unit test that shows the issue.

CacheTest {
    public void testCloneCompleteness() throws Exception {
        Cache cache = new Cache("testGetMemoryStore", 10, false, false, 100, 200);
        Cache clone = (Cache) cache.clone();
        // validate updating the statistics of one cache does NOT affect a
        cloned one
        assertEquals(1, cache.getStatistics().getCacheMisses());
        assertEquals(0, clone.getStatistics().getCacheMisses());

My guess is that at a minimum the following needs to be added

Cache {
    public final Object clone() throws CloneNotSupportedException {
        copy.hitCount = new AtomicLong();
        copy.memoryStoreHitCount = new AtomicLong();
        copy.diskStoreHitCount = new AtomicLong();
        copy.missCountNotFound = new AtomicLong();
        copy.missCountExpired = new AtomicLong();
        copy.totalGetTime = new AtomicLong();
        return copy;


Abhishek Singh 2009-09-26