/** * Gets the expected expiration, in milliseconds from the current time, for the entry corresponding to the given * {@code key}. * * @param key * @return The expiration duration in milliseconds * @throws NullPointerException if {@code key} is null * @throws NoSuchElementException If no entry exists for the given key */ public long getExpectedExpiration(K key) { Assert.notNull(key, "key"); ExpiringEntry<K, V> entry = getEntry(key); Assert.element(entry, key); return TimeUnit.NANOSECONDS.toMillis(entry.expectedExpiration.get() - System.nanoTime()); }
/** * Gets the expiration duration in milliseconds for the entry corresponding to the given key. * * @param key * @return The expiration duration in milliseconds * @throws NullPointerException if {@code key} is null * @throws NoSuchElementException If no entry exists for the given key */ public long getExpiration(K key) { Assert.notNull(key, "key"); ExpiringEntry<K, V> entry = getEntry(key); Assert.element(entry, key); return TimeUnit.NANOSECONDS.toMillis(entry.expirationNanos.get()); }
/** * Gets the expiration duration in milliseconds for the entry corresponding to the given key. * * @param key * @return The expiration duration in milliseconds * @throws NullPointerException if {@code key} is null * @throws NoSuchElementException If no entry exists for the given key */ public long getExpiration(K key) { Assert.notNull(key, "key"); ExpiringEntry<K, V> entry = getEntry(key); Assert.element(entry, key); return TimeUnit.NANOSECONDS.toMillis(entry.expirationNanos.get()); }
/** * Gets the expected expiration, in milliseconds from the current time, for the entry corresponding to the given * {@code key}. * * @param key * @return The expiration duration in milliseconds * @throws NullPointerException if {@code key} is null * @throws NoSuchElementException If no entry exists for the given key */ public long getExpectedExpiration(K key) { Assert.notNull(key, "key"); ExpiringEntry<K, V> entry = getEntry(key); Assert.element(entry, key); return TimeUnit.NANOSECONDS.toMillis(entry.expectedExpiration.get() - System.nanoTime()); }
/** * Gets the expected expiration, in milliseconds from the current time, for the entry corresponding to the given * {@code key}. * * @param key * @return The expiration duration in milliseconds * @throws NullPointerException if {@code key} is null * @throws NoSuchElementException If no entry exists for the given key */ public long getExpectedExpiration(K key) { Assert.notNull(key, "key"); ExpiringEntry<K, V> entry = getEntry(key); Assert.element(entry, key); return TimeUnit.NANOSECONDS.toMillis(entry.expectedExpiration.get() - System.nanoTime()); }
/** * Gets the expiration duration in milliseconds for the entry corresponding to the given key. * * @param key * @return The expiration duration in milliseconds * @throws NullPointerException if {@code key} is null * @throws NoSuchElementException If no entry exists for the given key */ public long getExpiration(K key) { Assert.notNull(key, "key"); ExpiringEntry<K, V> entry = getEntry(key); Assert.element(entry, key); return TimeUnit.NANOSECONDS.toMillis(entry.expirationNanos.get()); }
/** * Gets the ExpirationPolicy for the entry corresponding to the given {@code key}. * * @param key * @return The ExpirationPolicy for the {@code key} * @throws NullPointerException if {@code key} is null * @throws NoSuchElementException If no entry exists for the given key */ public ExpirationPolicy getExpirationPolicy(K key) { Assert.notNull(key, "key"); ExpiringEntry<K, V> entry = getEntry(key); Assert.element(entry, key); return entry.expirationPolicy.get(); }
/** * Gets the ExpirationPolicy for the entry corresponding to the given {@code key}. * * @param key * @return The ExpirationPolicy for the {@code key} * @throws NullPointerException if {@code key} is null * @throws NoSuchElementException If no entry exists for the given key */ public ExpirationPolicy getExpirationPolicy(K key) { Assert.notNull(key, "key"); ExpiringEntry<K, V> entry = getEntry(key); Assert.element(entry, key); return entry.expirationPolicy.get(); }
/** * Resets expiration for the entry corresponding to {@code key}. * * @param key to reset expiration for * @throws NullPointerException if {@code key} is null */ public void resetExpiration(K key) { Assert.notNull(key, "key"); ExpiringEntry<K, V> entry = getEntry(key); if (entry != null) resetEntry(entry, false); }
/** * Gets the ExpirationPolicy for the entry corresponding to the given {@code key}. * * @param key * @return The ExpirationPolicy for the {@code key} * @throws NullPointerException if {@code key} is null * @throws NoSuchElementException If no entry exists for the given key */ public ExpirationPolicy getExpirationPolicy(K key) { Assert.notNull(key, "key"); ExpiringEntry<K, V> entry = getEntry(key); Assert.element(entry, key); return entry.expirationPolicy.get(); }
/** * Resets expiration for the entry corresponding to {@code key}. * * @param key to reset expiration for * @throws NullPointerException if {@code key} is null */ public void resetExpiration(K key) { Assert.notNull(key, "key"); ExpiringEntry<K, V> entry = getEntry(key); if (entry != null) resetEntry(entry, false); }
/** * Resets expiration for the entry corresponding to {@code key}. * * @param key to reset expiration for * @throws NullPointerException if {@code key} is null */ public void resetExpiration(K key) { Assert.notNull(key, "key"); ExpiringEntry<K, V> entry = getEntry(key); if (entry != null) resetEntry(entry, false); }
/** * Sets the expiration policy for the entry corresponding to the given key. * * @param key to set policy for * @param expirationPolicy to set * @throws NullPointerException if {@code key} or {@code expirationPolicy} are null * @throws UnsupportedOperationException If variable expiration is not enabled */ public void setExpirationPolicy(K key, ExpirationPolicy expirationPolicy) { Assert.notNull(key, "key"); Assert.notNull(expirationPolicy, "expirationPolicy"); Assert.operation(variableExpiration, "Variable expiration is not enabled"); ExpiringEntry<K, V> entry = getEntry(key); if (entry != null) entry.expirationPolicy.set(expirationPolicy); }
/** * Sets the expiration policy for the entry corresponding to the given key. * * @param key to set policy for * @param expirationPolicy to set * @throws NullPointerException if {@code key} or {@code expirationPolicy} are null * @throws UnsupportedOperationException If variable expiration is not enabled */ public void setExpirationPolicy(K key, ExpirationPolicy expirationPolicy) { Assert.notNull(key, "key"); Assert.notNull(expirationPolicy, "expirationPolicy"); Assert.operation(variableExpiration, "Variable expiration is not enabled"); ExpiringEntry<K, V> entry = getEntry(key); if (entry != null) entry.expirationPolicy.set(expirationPolicy); }
@Override @SuppressWarnings("unchecked") public V get(Object key) { ExpiringEntry<K, V> entry = getEntry(key); if (entry == null) { return load((K) key); } else if (ExpirationPolicy.ACCESSED.equals(entry.expirationPolicy.get())) resetEntry(entry, false); return entry.getValue(); }
/** * Sets the expiration policy for the entry corresponding to the given key. * * @param key to set policy for * @param expirationPolicy to set * @throws NullPointerException if {@code key} or {@code expirationPolicy} are null * @throws UnsupportedOperationException If variable expiration is not enabled */ public void setExpirationPolicy(K key, ExpirationPolicy expirationPolicy) { Assert.notNull(key, "key"); Assert.notNull(expirationPolicy, "expirationPolicy"); Assert.operation(variableExpiration, "Variable expiration is not enabled"); ExpiringEntry<K, V> entry = getEntry(key); if (entry != null) entry.expirationPolicy.set(expirationPolicy); }
@Override @SuppressWarnings("unchecked") public V get(Object key) { ExpiringEntry<K, V> entry = getEntry(key); if (entry == null) { return load((K) key); } else if (ExpirationPolicy.ACCESSED.equals(entry.expirationPolicy.get())) resetEntry(entry, false); return entry.getValue(); }
@Override @SuppressWarnings("unchecked") public V get(Object key) { ExpiringEntry<K, V> entry = getEntry(key); if (entry == null) { return load((K) key); } else if (ExpirationPolicy.ACCESSED.equals(entry.expirationPolicy.get())) resetEntry(entry, false); return entry.getValue(); }
private V load(K key) { if (entryLoader == null && expiringEntryLoader == null) return null; writeLock.lock(); try { // Double check for entry ExpiringEntry<K, V> entry = getEntry(key); if (entry != null) return entry.getValue(); if (entryLoader != null) { V value = entryLoader.load(key); put(key, value); return value; } else { ExpiringValue<? extends V> expiringValue = expiringEntryLoader.load(key); if (expiringValue == null) { put(key, null); return null; } else { long duration = expiringValue.getTimeUnit() == null ? expirationNanos.get() : expiringValue.getDuration(); TimeUnit timeUnit = expiringValue.getTimeUnit() == null ? TimeUnit.NANOSECONDS : expiringValue.getTimeUnit(); put(key, expiringValue.getValue(), expiringValue.getExpirationPolicy() == null ? expirationPolicy.get() : expiringValue.getExpirationPolicy(), duration, timeUnit); return expiringValue.getValue(); } } } finally { writeLock.unlock(); } }
private V load(K key) { if (entryLoader == null && expiringEntryLoader == null) return null; writeLock.lock(); try { // Double check for entry ExpiringEntry<K, V> entry = getEntry(key); if (entry != null) return entry.getValue(); if (entryLoader != null) { V value = entryLoader.load(key); put(key, value); return value; } else { ExpiringValue<? extends V> expiringValue = expiringEntryLoader.load(key); if (expiringValue == null) { put(key, null); return null; } else { long duration = expiringValue.getTimeUnit() == null ? expirationNanos.get() : expiringValue.getDuration(); TimeUnit timeUnit = expiringValue.getTimeUnit() == null ? TimeUnit.NANOSECONDS : expiringValue.getTimeUnit(); put(key, expiringValue.getValue(), expiringValue.getExpirationPolicy() == null ? expirationPolicy.get() : expiringValue.getExpirationPolicy(), duration, timeUnit); return expiringValue.getValue(); } } } finally { writeLock.unlock(); } }