Interface Policy.VarExpiration<K,V>
- All Known Implementing Classes:
BoundedLocalCache.BoundedPolicy.BoundedVarExpiration
public static interface Policy.VarExpiration<K,V>
The low-level operations for a cache with a variable expiration policy.
-
Method Summary
Modifier and TypeMethodDescriptiongetExpiresAfter
(@NonNull K key) Returns the duration until the entry should be automatically removed.@NonNull OptionalLong
getExpiresAfter
(@NonNull K key, @NonNull TimeUnit unit) Returns the duration until the entry should be automatically removed.oldest
(@org.checkerframework.checker.index.qual.NonNegative int limit) Returns an unmodifiable snapshotMap
view of the cache with ordered traversal.default void
put
(@NonNull K key, @NonNull V value, @org.checkerframework.checker.index.qual.NonNegative long duration, @NonNull TimeUnit unit) Associates thevalue
with thekey
in this cache.default void
Associates thevalue
with thekey
in this cache.default boolean
putIfAbsent
(@NonNull K key, @NonNull V value, @org.checkerframework.checker.index.qual.NonNegative long duration, @NonNull TimeUnit unit) Associates thevalue
with thekey
in this cache if the specified key is not already associated with a value.default boolean
putIfAbsent
(@NonNull K key, @NonNull V value, @NonNull Duration duration) Associates thevalue
with thekey
in this cache if the specified key is not already associated with a value.void
setExpiresAfter
(@NonNull K key, @org.checkerframework.checker.index.qual.NonNegative long duration, @NonNull TimeUnit unit) Specifies that the entry should be automatically removed from the cache once the duration has elapsed.default void
setExpiresAfter
(@NonNull K key, @NonNull Duration duration) Specifies that the entry should be automatically removed from the cache once the duration has elapsed.youngest
(@org.checkerframework.checker.index.qual.NonNegative int limit) Returns an unmodifiable snapshotMap
view of the cache with ordered traversal.
-
Method Details
-
getExpiresAfter
Returns the duration until the entry should be automatically removed. The expiration policy determines when the entry's duration is reset.This method is scheduled for removal in version 3.0.0.
- Parameters:
key
- the key for the entry being queriedunit
- the unit thatage
is expressed in- Returns:
- the duration if the entry is present in the cache
-
getExpiresAfter
Returns the duration until the entry should be automatically removed. The expiration policy determines when the entry's duration is reset.- Parameters:
key
- the key for the entry being queried- Returns:
- the duration if the entry is present in the cache
-
setExpiresAfter
void setExpiresAfter(@NonNull K key, @org.checkerframework.checker.index.qual.NonNegative long duration, @NonNull TimeUnit unit) Specifies that the entry should be automatically removed from the cache once the duration has elapsed. The expiration policy determines when the entry's age is reset.- Parameters:
key
- the key for the entry being setduration
- the length of time from now when the entry should be automatically removedunit
- the unit thatduration
is expressed in- Throws:
IllegalArgumentException
- ifduration
is negativeNullPointerException
- if the unit is null
-
setExpiresAfter
Specifies that the entry should be automatically removed from the cache once the duration has elapsed. The expiration policy determines when the entry's age is reset.- Parameters:
key
- the key for the entry being setduration
- the length of time from now when the entry should be automatically removed- Throws:
IllegalArgumentException
- ifduration
is negative
-
putIfAbsent
default boolean putIfAbsent(@NonNull K key, @NonNull V value, @org.checkerframework.checker.index.qual.NonNegative long duration, @NonNull TimeUnit unit) Associates thevalue
with thekey
in this cache if the specified key is not already associated with a value. This method differs fromMap.putIfAbsent(K, V)
by substituting the configuredExpiry
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.
- Parameters:
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 thatduration
is expressed in- Returns:
true
if this cache did not already contain the specified entry- Throws:
IllegalArgumentException
- ifduration
is negative
-
putIfAbsent
Associates thevalue
with thekey
in this cache if the specified key is not already associated with a value. This method differs fromMap.putIfAbsent(K, V)
by substituting the configuredExpiry
with the specified write duration, has no effect on the duration if the entry was present, and returns the success rather than a value.- Parameters:
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 removed- Returns:
true
if this cache did not already contain the specified entry- Throws:
IllegalArgumentException
- ifduration
is negative
-
put
default void put(@NonNull K key, @NonNull V value, @org.checkerframework.checker.index.qual.NonNegative long duration, @NonNull TimeUnit unit) Associates thevalue
with thekey
in this cache. If the cache previously contained a value associated with thekey
, the old value is replaced by the newvalue
. This method differs fromCache.put(K, V)
by substituting the configuredExpiry
with the specified write duration.This method is scheduled for removal in version 3.0.0.
- Parameters:
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 thatduration
is expressed in- Throws:
IllegalArgumentException
- ifduration
is negativeNullPointerException
- if the specified key or value is null
-
put
Associates thevalue
with thekey
in this cache. If the cache previously contained a value associated with thekey
, the old value is replaced by the newvalue
. This method differs fromCache.put(K, V)
by substituting the configuredExpiry
with the specified write duration.- Parameters:
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 removed- Throws:
IllegalArgumentException
- ifduration
is negative
-
oldest
@NonNull Map<@NonNull K,@NonNull V> oldest(@org.checkerframework.checker.index.qual.NonNegative int limit) Returns an unmodifiable snapshotMap
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.
- Parameters:
limit
- the maximum size of the returned map (useInteger.MAX_VALUE
to disregard the limit)- Returns:
- a snapshot view of the cache from oldest entry to the youngest
-
youngest
@NonNull Map<@NonNull K,@NonNull V> youngest(@org.checkerframework.checker.index.qual.NonNegative int limit) Returns an unmodifiable snapshotMap
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.
- Parameters:
limit
- the maximum size of the returned map (useInteger.MAX_VALUE
to disregard the limit)- Returns:
- a snapshot view of the cache from youngest entry to the oldest
-