| Modifier and Type | Method and Description |
|---|---|
OptionalLong |
getExpiresAfter(K key,
TimeUnit unit)
Returns the duration until the entry should be automatically removed.
|
Map<K,V> |
oldest(int limit)
Returns an unmodifiable snapshot
Map view of the cache with ordered traversal. |
default void |
put(K key,
V value,
long duration,
TimeUnit unit)
Associates the
value with the key in this cache. |
default boolean |
putIfAbsent(K key,
V value,
long duration,
TimeUnit unit)
Associates the
value with the key in this cache if the specified key is not
already associated with a value. |
void |
setExpiresAfter(K key,
long duration,
TimeUnit unit)
Specifies that the entry should be automatically removed from the cache once the duration has
elapsed.
|
Map<K,V> |
youngest(int limit)
Returns an unmodifiable snapshot
Map view of the cache with ordered traversal. |
@Nonnull OptionalLong getExpiresAfter(@Nonnull K key, @Nonnull TimeUnit unit)
key - the key for the entry being queriedunit - the unit that age is expressed invoid setExpiresAfter(@Nonnull K key, @Nonnegative long duration, @Nonnull TimeUnit unit)
key - the key for the entry being setduration - the length of time from now when the entry should be automatically removedunit - the unit that duration is expressed inIllegalArgumentException - if duration is negativeNullPointerException - if the unit is nulldefault boolean putIfAbsent(@Nonnull K key, @Nonnull V value, @Nonnegative long duration, @Nonnull TimeUnit unit)
value with the key in this cache if the specified key is not
already associated with a value. This method differs from Map.putIfAbsent(K, V) by
substituting the configured Expiry with the specified write duration, has no effect
on the duration if the entry was present, and returns the success rather than a value.key - the key with which the specified value is to be associatedvalue - value to be associated with the specified keyduration - the length of time from now when the entry should be automatically removedunit - the unit that duration is expressed inIllegalArgumentException - if duration is negativeNullPointerException - if the specified key or value is nulldefault void put(@Nonnull K key, @Nonnull V value, @Nonnegative long duration, @Nonnull TimeUnit unit)
value with the key in this cache. If the cache previously
contained a value associated with the key, the old value is replaced by the new
value. This method differs from Cache.put(K, V) by substituting the
configured Expiry with the specified write duration.key - the key with which the specified value is to be associatedvalue - value to be associated with the specified keyduration - the length of time from now when the entry should be automatically removedunit - the unit that duration is expressed inIllegalArgumentException - if duration is negativeNullPointerException - if the specified key or value is null@Nonnull Map<K,V> oldest(@Nonnegative int limit)
Map view of the cache with ordered traversal. The
order of iteration is from the entries most likely to expire (oldest) to the entries least
likely to expire (youngest). This order is determined by the expiration policy's best guess
at the time of creating this snapshot view.
Beware that obtaining the mappings is NOT a constant-time operation. Because of the asynchronous nature of the page replacement policy, determining the retention ordering requires a traversal of the entries.
limit - the maximum size of the returned map (use Integer.MAX_VALUE to disregard
the limit)@Nonnull Map<K,V> youngest(@Nonnegative int limit)
Map view of the cache with ordered traversal. The
order of iteration is from the entries least likely to expire (youngest) to the entries most
likely to expire (oldest). This order is determined by the expiration policy's best guess at
the time of creating this snapshot view.
Beware that obtaining the mappings is NOT a constant-time operation. Because of the asynchronous nature of the page replacement policy, determining the retention ordering requires a traversal of the entries.
limit - the maximum size of the returned map (use Integer.MAX_VALUE to disregard
the limit)