@Test public void testReadFromCacheOnHit() { when(underlying.apply(onKey)).thenReturn(toggle); final CachingToggleMap<String, Integer> toggleMap = new CachingToggleMap<>(underlying, CaffeineSpec.parse("maximumSize=3")); toggleMap.apply(onKey).test(1); toggleMap.apply(onKey).test(2); verify(underlying, times(1)).apply(eq(onKey)); }
@Override public Toggle<T> apply(K key) { return new Toggle<T>() { @Override protected boolean test(T t, Optional<String> cohortOpt) { Toggle<T> underlying = null; try { underlying = cache.get(key); fallbackCache.put(key, underlying); } catch (NoSuchElementException err) { underlying = fallbackCache.getOrDefault(key, ALWAYS_FALSE); } if (cohortOpt.isPresent()) { return underlying .withCohort(cohortOpt.get()) .test(t); } else { return underlying.test(t); } } }; }
CachingToggleMap extends ToggleMap<K, T> { @Override public Toggle<T> apply(K key) { return new Toggle<T>() { @Override protected boolean test(T t, Optional<String> cohortOpt) { Toggle<T> underlying = null; try { underlying = cache.get(key); fallbackCache.put(key, underlying); } catch (NoSuchElementException err) { underlying = fallbackCache.getOrDefault(key, ALWAYS_FALSE); } if (cohortOpt.isPresent()) { return underlying .withCohort(cohortOpt.get()) .test(t); } else { return underlying.test(t); } } }; } }
CachingToggleMap extends ToggleMap<K, T> { @Override public Toggle<T> apply(K key) { return new Toggle<T>() { @Override protected boolean test(T t, Optional<String> cohortOpt) { Toggle<T> underlying = null; try { underlying = cache.get(key); fallbackCache.put(key, underlying); } catch (NoSuchElementException err) { underlying = fallbackCache.getOrDefault(key, ALWAYS_FALSE); } if (cohortOpt.isPresent()) { return underlying .withCohort(cohortOpt.get()) .test(t); } else { return underlying.test(t); } } }; } CachingToggleMap(ToggleMap<K, T> underlying, CaffeineSpec cacheSpec);  CachingToggleMap(ToggleMap<K, T> underlying, String cacheSpec); }
CachingToggleMap extends ToggleMap<K, T> { @Override public Toggle<T> apply(K key) { return new Toggle<T>() { @Override protected boolean test(T t, Optional<String> cohortOpt) { Toggle<T> underlying = null; try { underlying = cache.get(key); fallbackCache.put(key, underlying); } catch (NoSuchElementException err) { underlying = fallbackCache.getOrDefault(key, ALWAYS_FALSE); } if (cohortOpt.isPresent()) { return underlying .withCohort(cohortOpt.get()) .test(t); } else { return underlying.test(t); } } }; } CachingToggleMap(ToggleMap<K, T> underlying, CaffeineSpec cacheSpec);  CachingToggleMap(ToggleMap<K, T> underlying, String cacheSpec); @Override Toggle<T> apply(K key); @Override Set<K> keySet(); }
CachingToggleMap extends ToggleMap<K, T> { @Override public Toggle<T> apply(K key) { return new Toggle<T>() { @Override protected boolean test(T t, Optional<String> cohortOpt) { Toggle<T> underlying = null; try { underlying = cache.get(key); fallbackCache.put(key, underlying); } catch (NoSuchElementException err) { underlying = fallbackCache.getOrDefault(key, ALWAYS_FALSE); } if (cohortOpt.isPresent()) { return underlying .withCohort(cohortOpt.get()) .test(t); } else { return underlying.test(t); } } }; } CachingToggleMap(ToggleMap<K, T> underlying, CaffeineSpec cacheSpec);  CachingToggleMap(ToggleMap<K, T> underlying, String cacheSpec); @Override Toggle<T> apply(K key); @Override Set<K> keySet();  }