Modifier and Type | Method and Description |
---|---|
default @NonNull Optional<Duration> |
getExpiresAfter(K key)
Returns the duration until the entry should be automatically removed.
|
@NonNull OptionalLong |
getExpiresAfter(K key,
@NonNull TimeUnit unit)
Returns the duration until the entry should be automatically removed.
|
@NonNull 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,
@NonNull Duration duration)
Associates the
value with the key in this cache. |
default void |
put(K key,
V value,
long duration,
@NonNull TimeUnit unit)
Associates the
value with the key in this cache. |
default boolean |
putIfAbsent(K key,
V value,
@NonNull Duration duration)
Associates the
value with the key in this cache if the specified key is not
already associated with a value. |
default boolean |
putIfAbsent(K key,
V value,
long duration,
@NonNull TimeUnit unit)
Associates the
value with the key in this cache if the specified key is not
already associated with a value. |
default void |
setExpiresAfter(K key,
@NonNull Duration duration)
Specifies that the entry should be automatically removed from the cache once the duration has
elapsed.
|
void |
setExpiresAfter(K key,
long duration,
@NonNull TimeUnit unit)
Specifies that the entry should be automatically removed from the cache once the duration has
elapsed.
|
@NonNull Map<K,V> |
youngest(int limit)
Returns an unmodifiable snapshot
Map view of the cache with ordered traversal. |
@NonNull OptionalLong getExpiresAfter(K key, @NonNull TimeUnit unit)
This method is scheduled for removal in version 3.0.0.
key
- the key for the entry being queriedunit
- the unit that age
is expressed indefault @NonNull Optional<Duration> getExpiresAfter(K key)
key
- the key for the entry being queriedvoid setExpiresAfter(K key, 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 void setExpiresAfter(K key, @NonNull Duration duration)
key
- the key for the entry being setduration
- the length of time from now when the entry should be automatically removedIllegalArgumentException
- if duration
is negativedefault boolean putIfAbsent(K key, V value, 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.
This method is scheduled for removal in version 3.0.0.
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 negativedefault boolean putIfAbsent(K key, V value, @NonNull Duration duration)
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 removedIllegalArgumentException
- if duration
is negativedefault void put(K key, V value, 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.
This method is scheduled for removal in version 3.0.0.
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(K key, V value, @NonNull Duration duration)
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 removedIllegalArgumentException
- if duration
is negative@NonNull Map<K,V> oldest(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(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)