Commits

ltor...@81dbac14-341a-0410-aa85-cbcd92e6f43e  committed d7e1d61

Added getCapacity and getSize to caculate better cache stats
Issue number: Unkown issue no
Submitted by: Lars Torunski

  • Participants
  • Parent commits 6538209

Comments (0)

Files changed (2)

File src/java/com/opensymphony/oscache/base/Cache.java

 
         this.blocking = blocking;
     }
+    
+    /**
+     * @return the maximum number of items to cache can hold.
+     */
+    public int getCapacity() {
+    	return cacheMap.getMaxEntries();
+    }
 
     /**
      * Allows the capacity of the cache to be altered dynamically. Note that
             dispatchCacheEntryEvent(CacheEntryEventType.ENTRY_FLUSHED, event);
         }
     }
+    
+    /**
+     * @return the total number of cache entries held in this cache. 
+     */
+	public int getSize() {
+		synchronized(cacheMap) {
+			return cacheMap.size();
+		}
+	}
 
     /**
      * Test support only: return the number of EntryUpdateState instances within the updateStates map. 
     
     
     /**
-     * Test support only: return the number of entries currently in the cache map 
+     * Test support only: return the number of entries currently in the cache map
+     * @deprecated use getSize() 
      */
 	public int getNbEntries() {
 		synchronized(cacheMap) {

File src/test/java/com/opensymphony/oscache/base/TestCache.java

 			admin.putInCache(key, cacheValue);
 		}
         
-		Assert.assertEquals("expected cache to be at its full capacity", cacheCapacity , cache.getNbEntries());
+		Assert.assertEquals("expected cache to be at its full capacity", cacheCapacity , cache.getSize());
 		Assert.assertTrue("expected cache overflows to have cleaned UpdateState instances. got [" + cache.getNbUpdateState() + "] updates while max is [" + cacheCapacity + "]", cache.getNbUpdateState() <= cacheCapacity);
     }
 
 			}
 		}
         
-		Assert.assertEquals("expected cache to be at its full capacity", cacheCapacity , cache.getNbEntries());
+		Assert.assertEquals("expected cache to be at its full capacity", cacheCapacity , cache.getSize());
 		Assert.assertTrue("expected cache overflows to have cleaned UpdateState instances. Nb states is:" + cache.getNbUpdateState() + " expected max="+ cacheCapacity, cache.getNbUpdateState() <= cacheCapacity);
     }