@Test public void testPurge() { PersistentTokenCache<String> cache = new PersistentTokenCache<>(1l); cache.put("key", "val"); try { Thread.sleep(100l); } catch (InterruptedException x) { throw new Error(x); } assertThat(cache.size()).isEqualTo(1); cache.purge(); assertThat(cache.size()).isEqualTo(0); }
public void purge() { long time = System.currentTimeMillis(); if (time - latestWriteTime > expireMillis) { map.clear(); } else { Iterator<Value> values = map.values().iterator(); while (values.hasNext()) { if (time >= values.next().expire) { values.remove(); } else { break; } } } }
PersistentTokenCache { public void purge() { long time = System.currentTimeMillis(); if (time - latestWriteTime > expireMillis) { map.clear(); } else { Iterator<Value> values = map.values().iterator(); while (values.hasNext()) { if (time >= values.next().expire) { values.remove(); } else { break; } } } } }
PersistentTokenCache { public void purge() { long time = System.currentTimeMillis(); if (time - latestWriteTime > expireMillis) { map.clear(); } else { Iterator<Value> values = map.values().iterator(); while (values.hasNext()) { if (time >= values.next().expire) { values.remove(); } else { break; } } } } PersistentTokenCache(long expireMillis); }
PersistentTokenCache { public void purge() { long time = System.currentTimeMillis(); if (time - latestWriteTime > expireMillis) { map.clear(); } else { Iterator<Value> values = map.values().iterator(); while (values.hasNext()) { if (time >= values.next().expire) { values.remove(); } else { break; } } } } PersistentTokenCache(long expireMillis); T get(String key); void put(String key, T token); int size(); void purge(); }
PersistentTokenCache { public void purge() { long time = System.currentTimeMillis(); if (time - latestWriteTime > expireMillis) { map.clear(); } else { Iterator<Value> values = map.values().iterator(); while (values.hasNext()) { if (time >= values.next().expire) { values.remove(); } else { break; } } } } PersistentTokenCache(long expireMillis); T get(String key); void put(String key, T token); int size(); void purge();  }