@Test public void testEviction() { CacheManager manager = new LRUCacheManager(2); Cache<String, Object> cache = manager.getCache("cache", this.soft); String one = "1"; String two = "2"; String three = "3"; cache.put(one, one); cache.put(two, two); cache.put(three, three); assertThat(cache.size()).isEqualTo(2); assertThat(cache.get(one)).isNull(); assertThat(cache.get(two)).isNotNull(); assertThat(cache.get(three)).isNotNull(); }
@SuppressWarnings("unchecked") @Override public <K, V> Cache<K, V> getCache(final String name, boolean soft) { Cache<K, V> cache = (Cache<K, V>) caches.computeIfAbsent(name, n -> this.newCache(soft)); if ((soft && !(cache instanceof LRUSoftCache)) || (!soft && (cache instanceof LRUSoftCache))) { LOG.warn("Cache {} is being used in mixed 'soft' and 'hard' mode", name); } return cache; }
LRUCacheManager implements CacheManager { @SuppressWarnings("unchecked") @Override public <K, V> Cache<K, V> getCache(final String name, boolean soft) { Cache<K, V> cache = (Cache<K, V>) caches.computeIfAbsent(name, n -> this.newCache(soft)); if ((soft && !(cache instanceof LRUSoftCache)) || (!soft && (cache instanceof LRUSoftCache))) { LOG.warn("Cache {} is being used in mixed 'soft' and 'hard' mode", name); } return cache; } }
LRUCacheManager implements CacheManager { @SuppressWarnings("unchecked") @Override public <K, V> Cache<K, V> getCache(final String name, boolean soft) { Cache<K, V> cache = (Cache<K, V>) caches.computeIfAbsent(name, n -> this.newCache(soft)); if ((soft && !(cache instanceof LRUSoftCache)) || (!soft && (cache instanceof LRUSoftCache))) { LOG.warn("Cache {} is being used in mixed 'soft' and 'hard' mode", name); } return cache; } LRUCacheManager(final int maxElements); }
LRUCacheManager implements CacheManager { @SuppressWarnings("unchecked") @Override public <K, V> Cache<K, V> getCache(final String name, boolean soft) { Cache<K, V> cache = (Cache<K, V>) caches.computeIfAbsent(name, n -> this.newCache(soft)); if ((soft && !(cache instanceof LRUSoftCache)) || (!soft && (cache instanceof LRUSoftCache))) { LOG.warn("Cache {} is being used in mixed 'soft' and 'hard' mode", name); } return cache; } LRUCacheManager(final int maxElements); @Override void evictAll(); @SuppressWarnings("unchecked") @Override Cache<K, V> getCache(final String name, boolean soft); }
LRUCacheManager implements CacheManager { @SuppressWarnings("unchecked") @Override public <K, V> Cache<K, V> getCache(final String name, boolean soft) { Cache<K, V> cache = (Cache<K, V>) caches.computeIfAbsent(name, n -> this.newCache(soft)); if ((soft && !(cache instanceof LRUSoftCache)) || (!soft && (cache instanceof LRUSoftCache))) { LOG.warn("Cache {} is being used in mixed 'soft' and 'hard' mode", name); } return cache; } LRUCacheManager(final int maxElements); @Override void evictAll(); @SuppressWarnings("unchecked") @Override Cache<K, V> getCache(final String name, boolean soft);  }