Interface RedisCacheWriter.TtlFunction
- All Known Implementing Classes:
FixedDurationTtlFunction
- Enclosing interface:
- RedisCacheWriter
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Function to compute the time to live from the cache
key
and value
.- Since:
- 3.2
- Author:
- Mark Paluch
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetTimeToLive
(Object key, Object value) static RedisCacheWriter.TtlFunction
Creates a SingletonRedisCacheWriter.TtlFunction
using the givenDuration
.static RedisCacheWriter.TtlFunction
Returns aRedisCacheWriter.TtlFunction
to create persistent entires that do not expire.
-
Field Details
-
NO_EXPIRATION
-
-
Method Details
-
just
Creates a SingletonRedisCacheWriter.TtlFunction
using the givenDuration
.- Parameters:
duration
- the time to live. Can beDuration.ZERO
for persistent values (i.e. cache entry does not expire).- Returns:
- a singleton
RedisCacheWriter.TtlFunction
usingDuration
.
-
persistent
Returns aRedisCacheWriter.TtlFunction
to create persistent entires that do not expire.- Returns:
- a
RedisCacheWriter.TtlFunction
to create persistent entires that do not expire.
-
getTimeToLive
Compute atime-to-live (TTL)
using the cachekey
andvalue
.The
time-to-live (TTL)
is computed on each write operation. Redis uses millisecond granularity for timeouts. Any more granular values (e.g. micros or nanos) are not considered and will be truncated due to rounding. ReturningDuration.ZERO
, or a value less thanDuration.ofMillis(1)
, results in a persistent value that does not expire.- Parameters:
key
- the cache key.value
- the cache value. Can be null if the cache supports null value caching.- Returns:
- the computed
time-to-live (TTL)
. Can beDuration.ZERO
for persistent values (i.e. cache entry does not expire).
-