@Test public void testCleanUpObsoleteEntries() throws InterruptedException { ObjectCache<String, String> cache = createCacheWith4Entries(1); Thread.sleep(3); cache.checkCleanUpObsoleteEntries(); assertEquals(0, cache.size()); assertEquals(4, cache.getCountExpired()); }
public synchronized int cleanUpObsoleteEntries() { countPutCountSinceEviction = 0; nextCleanUpTimestamp = 0; int countCleaned = 0; long timeLimit = isExpiring ? System.currentTimeMillis() - expirationMillis : 0; Iterator<CacheEntry<VALUE>> iterator = values.values().iterator(); while (iterator.hasNext()) { CacheEntry<VALUE> cacheEntry = iterator.next(); if (!isStrongReference && cacheEntry.reference == null) { countRefCleared++; countCleaned++; iterator.remove(); } else if (cacheEntry.timeCreated < timeLimit) { countExpired++; countCleaned++; iterator.remove(); } } return countCleaned; }
ObjectCache { public synchronized int cleanUpObsoleteEntries() { countPutCountSinceEviction = 0; nextCleanUpTimestamp = 0; int countCleaned = 0; long timeLimit = isExpiring ? System.currentTimeMillis() - expirationMillis : 0; Iterator<CacheEntry<VALUE>> iterator = values.values().iterator(); while (iterator.hasNext()) { CacheEntry<VALUE> cacheEntry = iterator.next(); if (!isStrongReference && cacheEntry.reference == null) { countRefCleared++; countCleaned++; iterator.remove(); } else if (cacheEntry.timeCreated < timeLimit) { countExpired++; countCleaned++; iterator.remove(); } } return countCleaned; } }
ObjectCache { public synchronized int cleanUpObsoleteEntries() { countPutCountSinceEviction = 0; nextCleanUpTimestamp = 0; int countCleaned = 0; long timeLimit = isExpiring ? System.currentTimeMillis() - expirationMillis : 0; Iterator<CacheEntry<VALUE>> iterator = values.values().iterator(); while (iterator.hasNext()) { CacheEntry<VALUE> cacheEntry = iterator.next(); if (!isStrongReference && cacheEntry.reference == null) { countRefCleared++; countCleaned++; iterator.remove(); } else if (cacheEntry.timeCreated < timeLimit) { countExpired++; countCleaned++; iterator.remove(); } } return countCleaned; } ObjectCache(ReferenceType referenceType, int maxSize, long expirationMillis); }
ObjectCache { public synchronized int cleanUpObsoleteEntries() { countPutCountSinceEviction = 0; nextCleanUpTimestamp = 0; int countCleaned = 0; long timeLimit = isExpiring ? System.currentTimeMillis() - expirationMillis : 0; Iterator<CacheEntry<VALUE>> iterator = values.values().iterator(); while (iterator.hasNext()) { CacheEntry<VALUE> cacheEntry = iterator.next(); if (!isStrongReference && cacheEntry.reference == null) { countRefCleared++; countCleaned++; iterator.remove(); } else if (cacheEntry.timeCreated < timeLimit) { countExpired++; countCleaned++; iterator.remove(); } } return countCleaned; } 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 int cleanUpObsoleteEntries() { countPutCountSinceEviction = 0; nextCleanUpTimestamp = 0; int countCleaned = 0; long timeLimit = isExpiring ? System.currentTimeMillis() - expirationMillis : 0; Iterator<CacheEntry<VALUE>> iterator = values.values().iterator(); while (iterator.hasNext()) { CacheEntry<VALUE> cacheEntry = iterator.next(); if (!isStrongReference && cacheEntry.reference == null) { countRefCleared++; countCleaned++; iterator.remove(); } else if (cacheEntry.timeCreated < timeLimit) { countExpired++; countCleaned++; iterator.remove(); } } return countCleaned; } 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();  }