K
- the key type for the cacheV
- the value type for the cachepublic interface ExpiryPolicy<K,V>
Cache
.
Previous values are not accessible directly but are rather available through a value Supplier
to indicate that access can require computation (such as deserialization).
Negative durations
are not supported, expiry policy implementation returning such a
duration will result in immediate expiry, as if the duration was zero
.
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
Modifier and Type | Field and Description |
---|---|
static java.time.Duration |
INFINITE
A
duration that represents an infinite time. |
static ExpiryPolicy<java.lang.Object,java.lang.Object> |
NO_EXPIRY
An
ExpiryPolicy that represents a no expiration policy |
Modifier and Type | Method and Description |
---|---|
java.time.Duration |
getExpiryForAccess(K key,
java.util.function.Supplier<? extends V> value)
|
java.time.Duration |
getExpiryForCreation(K key,
V value)
Returns the lifetime of an entry when it is initially added to a
Cache . |
java.time.Duration |
getExpiryForUpdate(K key,
java.util.function.Supplier<? extends V> oldValue,
V newValue)
|
static final java.time.Duration INFINITE
duration
that represents an infinite time.static final ExpiryPolicy<java.lang.Object,java.lang.Object> NO_EXPIRY
ExpiryPolicy
that represents a no expiration policyjava.time.Duration getExpiryForCreation(K key, V value)
Cache
.
This method must not return null
.
Exceptions thrown from this method will be swallowed and result in the expiry duration being
ZERO
.
key
- the key of the newly added entryvalue
- the value of the newly added entryDuration
java.time.Duration getExpiryForAccess(K key, java.util.function.Supplier<? extends V> value)
duration
(relative to the current time) when an existing entry
is accessed from a Cache
.
Returning null
indicates that the expiration time remains unchanged.
Exceptions thrown from this method will be swallowed and result in the expiry duration being
ZERO
.
key
- the key of the accessed entryvalue
- a value supplier for the accessed entryDuration
, null
means unchangedjava.time.Duration getExpiryForUpdate(K key, java.util.function.Supplier<? extends V> oldValue, V newValue)
duration
(relative to the current time) when an existing entry
is updated in a Cache
.
Returning null
indicates that the expiration time remains unchanged.
Exceptions thrown from this method will be swallowed and result in the expiry duration being
ZERO
.
key
- the key of the updated entryoldValue
- a value supplier for the previous value of the entrynewValue
- the new value of the entryDuration
, null
means unchanged