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. |
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 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)