LocalCacheStore implements CacheStore { public void cleanup() { logger.info("clean up local cache store"); long now = System.currentTimeMillis(); caches.values().removeIf(item -> item.expired(now)); int size = caches.size(); if (size > maxSize) { logger.info("evict least frequently used cache items, currentSize={}, maxSize={}", size, maxSize); int evictSize = size - maxSize; evictLeastFrequentlyUsedItems(evictSize); } }  @Override T get(String key, CacheContext<T> context); @Override Map<String, T> getAll(String[] keys, CacheContext<T> context); @Override void put(String key, T value, Duration expiration, CacheContext<T> context); @Override void putAll(List<Entry<T>> values, Duration expiration, CacheContext<T> context); @Override boolean delete(String... keys); void cleanup(); void clear(); public int maxSize; }
@Test void cleanup() { cacheStore.put("key1", new TestCache(), Duration.ZERO, null); cacheStore.put("key2", new TestCache(), Duration.ofMinutes(1), null); cacheStore.cleanup(); assertThat(cacheStore.caches).hasSize(1); }