Modifier and Type | Method and Description |
---|---|
OptionalLong |
ageOf(K key,
TimeUnit unit)
Returns the age of the entry based on the expiration policy.
|
long |
getExpiresAfter(TimeUnit unit)
Returns the fixed duration used to determine if an entry should be automatically removed due
to elapsing this time bound.
|
Map<K,V> |
oldest(int limit)
Returns an unmodifiable snapshot
Map view of the cache with ordered traversal. |
void |
setExpiresAfter(long duration,
TimeUnit unit)
Specifies that each entry should be automatically removed from the cache once a fixed
duration has elapsed based.
|
Map<K,V> |
youngest(int limit)
Returns an unmodifiable snapshot
Map view of the cache with ordered traversal. |
@Nonnull OptionalLong ageOf(@Nonnull K key, @Nonnull TimeUnit unit)
An expiration policy uses the age to determine if an entry is fresh or stale by comparing it
to the freshness lifetime. This is calculated as fresh = freshnessLifetime > age
where freshnessLifetime = expires - currentTime
.
key
- key with which the specified value is to be associatedunit
- the unit that age
is expressed in@Nonnegative long getExpiresAfter(@Nonnull TimeUnit unit)
unit
- the unit that duration is expressed invoid setExpiresAfter(@Nonnegative long duration, @Nonnull TimeUnit unit)
duration
- the length of time after which an entry should be automatically removedunit
- the unit that duration
is expressed inIllegalArgumentException
- if duration
is negative@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 to 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 to 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)