LeastRecentlyUsedCache { public final boolean update(K key) { if (key == null) { return false; } CacheEntry<K, V> entry = cache.get(key); if (entry == null) { return false; } entry.recordAccess(header); return true; } LeastRecentlyUsedCache();  LeastRecentlyUsedCache(final int capacity, final long threshold);  LeastRecentlyUsedCache(final int initialCapacity, final int maxCapacity, final long threshold); void addEvictionListener(EvictionListener<V> listener); boolean isEvictingOnReadAccess(); void setEvictingOnReadAccess(boolean evict); boolean isUpdatingOnReadAccess(); void setUpdatingOnReadAccess(boolean update); final long getExpirationThreshold(); final void setExpirationThreshold(long newThreshold); final void setExpirationThreshold(long newThreshold, TimeUnit unit); final int getCapacity(); final void setCapacity(int capacity); final int size(); final int remainingCapacity(); final void clear(); final boolean put(K key, V value); final V get(K key); final boolean update(K key); final V remove(K key); final V remove(K key, V value); final V find(Predicate<V> predicate); final V find(Predicate<V> predicate, boolean unique); final Iterator<V> valuesIterator(); final Collection<V> values(); static final int DEFAULT_INITIAL_CAPACITY; static final long DEFAULT_THRESHOLD_SECS; static final int DEFAULT_CAPACITY; }
@Test public void testUpdate() throws InterruptedException { int capacity = 5; int numberOfSessions = 1; TimeAssume assume = new TimeAssume(); givenACacheWithEntries(capacity, THRESHOLD_MILLIS, numberOfSessions); cache.setEvictingOnReadAccess(true); cache.setUpdatingOnReadAccess(false); String eldest = cache.getEldest(); Integer key = Integer.valueOf(eldest); assume.sleep(THRESHOLD_MILLIS / 2); assertThat(cache.get(key), assume.inTime(is(notNullValue()))); assertThat(cache.update(key), assume.inTime(is(true))); assume.sleep((THRESHOLD_MILLIS / 2) + 100); assertThat(cache.get(key), assume.inTime(is(notNullValue()))); assertThat(cache.update(key), assume.inTime(is(true))); assume.sleep(THRESHOLD_MILLIS / 2); assertThat(cache.get(key), assume.inTime(is(notNullValue()))); assume.sleep((THRESHOLD_MILLIS / 2) + 100); assertThat(cache.get(key), assume.inTime(is(nullValue()))); }