Interface ExpiryPolicy<K,V>
-
- Type Parameters:
K- the key type for the cacheV- the value type for the cache
public interface ExpiryPolicy<K,V>A policy object that governs expiration for mappings in aCache.Previous values are not accessible directly but are rather available through a value
Supplierto indicate that access can require computation (such as deserialization).Negative durationsare not supported, expiry policy implementation returning such a duration will result in immediate expiry, as if the duration waszero.NOTE: Some cache configurations (eg. caches with eventual consistency) may use local (ie. non-consistent) state to decide whether to call
getExpiryForUpdate(Object, Supplier, Object)vs.getExpiryForCreation(Object, Object). For these cache configurations it is advised to return the same value for both of these methods
-
-
Field Summary
Fields Modifier and Type Field Description static java.time.DurationINFINITEAdurationthat represents an infinite time.static ExpiryPolicy<java.lang.Object,java.lang.Object>NO_EXPIRYAnExpiryPolicythat represents a no expiration policy
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.time.DurationgetExpiryForAccess(K key, java.util.function.Supplier<? extends V> value)Returns the expirationduration(relative to the current time) when an existing entry is accessed from aCache.java.time.DurationgetExpiryForCreation(K key, V value)Returns the lifetime of an entry when it is initially added to aCache.java.time.DurationgetExpiryForUpdate(K key, java.util.function.Supplier<? extends V> oldValue, V newValue)Returns the expirationduration(relative to the current time) when an existing entry is updated in aCache.
-
-
-
Field Detail
-
INFINITE
static final java.time.Duration INFINITE
Adurationthat represents an infinite time.
-
NO_EXPIRY
static final ExpiryPolicy<java.lang.Object,java.lang.Object> NO_EXPIRY
AnExpiryPolicythat represents a no expiration policy
-
-
Method Detail
-
getExpiryForCreation
java.time.Duration getExpiryForCreation(K key, V value)
Returns the lifetime of an entry when it is initially added to aCache.This method must not return
null.Exceptions thrown from this method will be swallowed and result in the expiry duration being
ZERO.- Parameters:
key- the key of the newly added entryvalue- the value of the newly added entry- Returns:
- a non-null
Duration
-
getExpiryForAccess
java.time.Duration getExpiryForAccess(K key, java.util.function.Supplier<? extends V> value)
Returns the expirationduration(relative to the current time) when an existing entry is accessed from aCache.Returning
nullindicates that the expiration time remains unchanged.Exceptions thrown from this method will be swallowed and result in the expiry duration being
ZERO.- Parameters:
key- the key of the accessed entryvalue- a value supplier for the accessed entry- Returns:
- an expiration
Duration,nullmeans unchanged
-
getExpiryForUpdate
java.time.Duration getExpiryForUpdate(K key, java.util.function.Supplier<? extends V> oldValue, V newValue)
Returns the expirationduration(relative to the current time) when an existing entry is updated in aCache.Returning
nullindicates that the expiration time remains unchanged.Exceptions thrown from this method will be swallowed and result in the expiry duration being
ZERO.- Parameters:
key- the key of the updated entryoldValue- a value supplier for the previous value of the entrynewValue- the new value of the entry- Returns:
- an expiration
Duration,nullmeans unchanged
-
-