/** * Returns the internal ExpiringEntry for the {@code key}, obtaining a read lock. */ ExpiringEntry<K, V> getEntry(Object key) { readLock.lock(); try { return entries.get(key); } finally { readLock.unlock(); } }
/** * Returns the internal ExpiringEntry for the {@code key}, obtaining a read lock. */ ExpiringEntry<K, V> getEntry(Object key) { readLock.lock(); try { return entries.get(key); } finally { readLock.unlock(); } }
/** * Returns the internal ExpiringEntry for the {@code key}, obtaining a read lock. */ ExpiringEntry<K, V> getEntry(Object key) { readLock.lock(); try { return entries.get(key); } finally { readLock.unlock(); } }
writeLock.lock(); try { ExpiringEntry<K, V> entry = entries.get(key); V oldValue = null;
writeLock.lock(); try { ExpiringEntry<K, V> entry = entries.get(key); V oldValue = null;
writeLock.lock(); try { ExpiringEntry<K, V> entry = entries.get(key); V oldValue = null;
/** * Sets the expiration duration for the entry corresponding to the given key. Supported only if variable expiration is * enabled. * * @param key Key to set expiration for * @param duration the length of time after an entry is created that it should be removed * @param timeUnit the unit that {@code duration} is expressed in * @throws NullPointerException if {@code key} or {@code timeUnit} are null * @throws UnsupportedOperationException If variable expiration is not enabled */ public void setExpiration(K key, long duration, TimeUnit timeUnit) { Assert.notNull(key, "key"); Assert.notNull(timeUnit, "timeUnit"); Assert.operation(variableExpiration, "Variable expiration is not enabled"); writeLock.lock(); try { ExpiringEntry<K, V> entry = entries.get(key); if (entry != null) { entry.expirationNanos.set(TimeUnit.NANOSECONDS.convert(duration, timeUnit)); resetEntry(entry, true); } } finally { writeLock.unlock(); } }
/** * Sets the expiration duration for the entry corresponding to the given key. Supported only if variable expiration is * enabled. * * @param key Key to set expiration for * @param duration the length of time after an entry is created that it should be removed * @param timeUnit the unit that {@code duration} is expressed in * @throws NullPointerException if {@code key} or {@code timeUnit} are null * @throws UnsupportedOperationException If variable expiration is not enabled */ public void setExpiration(K key, long duration, TimeUnit timeUnit) { Assert.notNull(key, "key"); Assert.notNull(timeUnit, "timeUnit"); Assert.operation(variableExpiration, "Variable expiration is not enabled"); writeLock.lock(); try { ExpiringEntry<K, V> entry = entries.get(key); if (entry != null) { entry.expirationNanos.set(TimeUnit.NANOSECONDS.convert(duration, timeUnit)); resetEntry(entry, true); } } finally { writeLock.unlock(); } }
/** * Sets the expiration duration for the entry corresponding to the given key. Supported only if variable expiration is * enabled. * * @param key Key to set expiration for * @param duration the length of time after an entry is created that it should be removed * @param timeUnit the unit that {@code duration} is expressed in * @throws NullPointerException if {@code key} or {@code timeUnit} are null * @throws UnsupportedOperationException If variable expiration is not enabled */ public void setExpiration(K key, long duration, TimeUnit timeUnit) { Assert.notNull(key, "key"); Assert.notNull(timeUnit, "timeUnit"); Assert.operation(variableExpiration, "Variable expiration is not enabled"); writeLock.lock(); try { ExpiringEntry<K, V> entry = entries.get(key); if (entry != null) { entry.expirationNanos.set(TimeUnit.NANOSECONDS.convert(duration, timeUnit)); resetEntry(entry, true); } } finally { writeLock.unlock(); } }
@Override public boolean remove(Object key, Object value) { Assert.notNull(key, "key"); writeLock.lock(); try { ExpiringEntry<K, V> entry = entries.get(key); if (entry != null && entry.getValue().equals(value)) { entries.remove(key); if (entry.cancel()) scheduleEntry(entries.first()); return true; } else return false; } finally { writeLock.unlock(); } }
@Override public boolean remove(Object key, Object value) { Assert.notNull(key, "key"); writeLock.lock(); try { ExpiringEntry<K, V> entry = entries.get(key); if (entry != null && entry.getValue().equals(value)) { entries.remove(key); if (entry.cancel()) scheduleEntry(entries.first()); return true; } else return false; } finally { writeLock.unlock(); } }
@Override public boolean remove(Object key, Object value) { Assert.notNull(key, "key"); writeLock.lock(); try { ExpiringEntry<K, V> entry = entries.get(key); if (entry != null && entry.getValue().equals(value)) { entries.remove(key); if (entry.cancel()) scheduleEntry(entries.first()); return true; } else return false; } finally { writeLock.unlock(); } }
@Override public boolean replace(K key, V oldValue, V newValue) { Assert.notNull(key, "key"); writeLock.lock(); try { ExpiringEntry<K, V> entry = entries.get(key); if (entry != null && entry.getValue().equals(oldValue)) { putInternal(key, newValue, expirationPolicy.get(), expirationNanos.get()); return true; } else return false; } finally { writeLock.unlock(); } }
@Override public boolean replace(K key, V oldValue, V newValue) { Assert.notNull(key, "key"); writeLock.lock(); try { ExpiringEntry<K, V> entry = entries.get(key); if (entry != null && entry.getValue().equals(oldValue)) { putInternal(key, newValue, expirationPolicy.get(), expirationNanos.get()); return true; } else return false; } finally { writeLock.unlock(); } }
@Override public boolean replace(K key, V oldValue, V newValue) { Assert.notNull(key, "key"); writeLock.lock(); try { ExpiringEntry<K, V> entry = entries.get(key); if (entry != null && entry.getValue().equals(oldValue)) { putInternal(key, newValue, expirationPolicy.get(), expirationNanos.get()); return true; } else return false; } finally { writeLock.unlock(); } }
@Override public V putIfAbsent(K key, V value) { Assert.notNull(key, "key"); writeLock.lock(); try { if (!entries.containsKey(key)) return putInternal(key, value, expirationPolicy.get(), expirationNanos.get()); else return entries.get(key).getValue(); } finally { writeLock.unlock(); } }
@Override public V putIfAbsent(K key, V value) { Assert.notNull(key, "key"); writeLock.lock(); try { if (!entries.containsKey(key)) return putInternal(key, value, expirationPolicy.get(), expirationNanos.get()); else return entries.get(key).getValue(); } finally { writeLock.unlock(); } }
@Override public V putIfAbsent(K key, V value) { Assert.notNull(key, "key"); writeLock.lock(); try { if (!entries.containsKey(key)) return putInternal(key, value, expirationPolicy.get(), expirationNanos.get()); else return entries.get(key).getValue(); } finally { writeLock.unlock(); } }