Class BoundedLocalCache.BoundedPolicy.BoundedVarExpiration
- java.lang.Object
-
- com.github.benmanes.caffeine.cache.BoundedLocalCache.BoundedPolicy.BoundedVarExpiration
-
- All Implemented Interfaces:
Policy.VarExpiration<K,V>
- Enclosing class:
- BoundedLocalCache.BoundedPolicy<K,V>
final class BoundedLocalCache.BoundedPolicy.BoundedVarExpiration extends java.lang.Object implements Policy.VarExpiration<K,V>
-
-
Constructor Summary
Constructors Constructor Description BoundedVarExpiration()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.OptionalLong
getExpiresAfter(K key, java.util.concurrent.TimeUnit unit)
Returns the duration until the entry should be automatically removed.java.util.Map<K,V>
oldest(int limit)
Returns an unmodifiable snapshotMap
view of the cache with ordered traversal.void
put(K key, V value, long duration, java.util.concurrent.TimeUnit unit)
Associates thevalue
with thekey
in this cache.(package private) @Nullable V
put(K key, V value, long duration, java.util.concurrent.TimeUnit unit, boolean onlyIfAbsent)
boolean
putIfAbsent(K key, V value, long duration, java.util.concurrent.TimeUnit unit)
Associates thevalue
with thekey
in this cache if the specified key is not already associated with a value.void
setExpiresAfter(K key, long duration, java.util.concurrent.TimeUnit unit)
Specifies that the entry should be automatically removed from the cache once the duration has elapsed.java.util.Map<K,V>
youngest(int limit)
Returns an unmodifiable snapshotMap
view of the cache with ordered traversal.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.github.benmanes.caffeine.cache.Policy.VarExpiration
getExpiresAfter, put, putIfAbsent, setExpiresAfter
-
-
-
-
Method Detail
-
getExpiresAfter
public java.util.OptionalLong getExpiresAfter(K key, java.util.concurrent.TimeUnit unit)
Description copied from interface:Policy.VarExpiration
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.
- Specified by:
getExpiresAfter
in interfacePolicy.VarExpiration<K,V>
- 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
-
setExpiresAfter
public void setExpiresAfter(K key, long duration, java.util.concurrent.TimeUnit unit)
Description copied from interface:Policy.VarExpiration
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.- Specified by:
setExpiresAfter
in interfacePolicy.VarExpiration<K,V>
- 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
-
put
public void put(K key, V value, long duration, java.util.concurrent.TimeUnit unit)
Description copied from interface:Policy.VarExpiration
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.
- Specified by:
put
in interfacePolicy.VarExpiration<K,V>
- 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
-
putIfAbsent
public boolean putIfAbsent(K key, V value, long duration, java.util.concurrent.TimeUnit unit)
Description copied from interface:Policy.VarExpiration
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.
- Specified by:
putIfAbsent
in interfacePolicy.VarExpiration<K,V>
- 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
-
put
@Nullable V put(K key, V value, long duration, java.util.concurrent.TimeUnit unit, boolean onlyIfAbsent)
-
oldest
public java.util.Map<K,V> oldest(int limit)
Description copied from interface:Policy.VarExpiration
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.
- Specified by:
oldest
in interfacePolicy.VarExpiration<K,V>
- 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
public java.util.Map<K,V> youngest(int limit)
Description copied from interface:Policy.VarExpiration
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.
- Specified by:
youngest
in interfacePolicy.VarExpiration<K,V>
- 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
-
-