@Test public void testEvictToTargetSize() { ObjectCache<String, String> cache = createCacheWith4Entries(0); cache.evictToTargetSize(2); assertEquals(2, cache.size()); assertEquals(cache.get("3"), "c"); assertEquals(cache.get("4"), "d"); cache.evictToTargetSize(0); assertEquals(0, cache.size()); }
public synchronized void evictToTargetSize(int targetSize) { if (targetSize <= 0) { values.clear(); } else { checkCleanUpObsoleteEntries(); Iterator<KEY> keys = values.keySet().iterator(); while (keys.hasNext() && values.size() > targetSize) { countEvicted++; keys.next(); keys.remove(); } } }
ObjectCache { public synchronized void evictToTargetSize(int targetSize) { if (targetSize <= 0) { values.clear(); } else { checkCleanUpObsoleteEntries(); Iterator<KEY> keys = values.keySet().iterator(); while (keys.hasNext() && values.size() > targetSize) { countEvicted++; keys.next(); keys.remove(); } } } }
ObjectCache { public synchronized void evictToTargetSize(int targetSize) { if (targetSize <= 0) { values.clear(); } else { checkCleanUpObsoleteEntries(); Iterator<KEY> keys = values.keySet().iterator(); while (keys.hasNext() && values.size() > targetSize) { countEvicted++; keys.next(); keys.remove(); } } } ObjectCache(ReferenceType referenceType, int maxSize, long expirationMillis); }
ObjectCache { public synchronized void evictToTargetSize(int targetSize) { if (targetSize <= 0) { values.clear(); } else { checkCleanUpObsoleteEntries(); Iterator<KEY> keys = values.keySet().iterator(); while (keys.hasNext() && values.size() > targetSize) { countEvicted++; keys.next(); keys.remove(); } } } ObjectCache(ReferenceType referenceType, int maxSize, long expirationMillis); VALUE put(KEY key, VALUE object); void putAll(Map<KEY, VALUE> mapDataToPut); VALUE get(KEY key); synchronized void clear(); VALUE remove(KEY key); synchronized void evictToTargetSize(int targetSize); synchronized int cleanUpObsoleteEntries(); synchronized boolean containsKey(KEY key); boolean containsKeyWithValue(KEY key); synchronized Set<KEY> keySet(); int getMaxSize(); synchronized int size(); int getCountPut(); int getCountHit(); int getCountMiss(); int getCountExpired(); int getCountRefCleared(); int getCountEvicted(); @Override String toString(); String getStatsStringRemoved(); }
ObjectCache { public synchronized void evictToTargetSize(int targetSize) { if (targetSize <= 0) { values.clear(); } else { checkCleanUpObsoleteEntries(); Iterator<KEY> keys = values.keySet().iterator(); while (keys.hasNext() && values.size() > targetSize) { countEvicted++; keys.next(); keys.remove(); } } } ObjectCache(ReferenceType referenceType, int maxSize, long expirationMillis); VALUE put(KEY key, VALUE object); void putAll(Map<KEY, VALUE> mapDataToPut); VALUE get(KEY key); synchronized void clear(); VALUE remove(KEY key); synchronized void evictToTargetSize(int targetSize); synchronized int cleanUpObsoleteEntries(); synchronized boolean containsKey(KEY key); boolean containsKeyWithValue(KEY key); synchronized Set<KEY> keySet(); int getMaxSize(); synchronized int size(); int getCountPut(); int getCountHit(); int getCountMiss(); int getCountExpired(); int getCountRefCleared(); int getCountEvicted(); @Override String toString(); String getStatsStringRemoved();  }