Interface RMapCacheReactive<K,V>
- Type Parameters:
K
- keyV
- value
- All Superinterfaces:
RDestroyable
,RExpirableReactive
,RMapReactive<K,
,V> RObjectReactive
Map-based cache with ability to set TTL for each entry via
put(Object, Object, long, TimeUnit)
or putIfAbsent(Object, Object, long, TimeUnit)
method.
And therefore has an complex lua-scripts inside.
Current redis implementation doesnt have map entry eviction functionality.
Thus entries are checked for TTL expiration during any key/value/entry read operation.
If key/value/entry expired then it doesn't returns and clean task runs asynchronous.
Clean task deletes removes 100 expired entries at once.
In addition there is EvictionScheduler
. This scheduler
deletes expired entries in time interval between 5 seconds to 2 hours.
If eviction is not required then it's better to use RedissonMapReactive
.
- Author:
- Nikita Koksharov
-
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono
<Integer> addListener
(MapEntryListener listener) Adds map entry listenerreactor.core.publisher.Mono
<V> If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map .reactor.core.publisher.Mono
<Integer> expireEntries
(Set<K> keys, Duration ttl, Duration maxIdleTime) Updates time to live and max idle time of specified entries by keys.reactor.core.publisher.Mono
<Integer> expireEntriesIfNotSet
(Set<K> keys, Duration ttl, Duration maxIdleTime) Sets time to live and max idle time of specified entries by keys.reactor.core.publisher.Mono
<Boolean> expireEntry
(K key, Duration ttl, Duration maxIdleTime) Updates time to live and max idle time of specified entry by key.reactor.core.publisher.Mono
<Boolean> expireEntryIfNotSet
(K key, Duration ttl, Duration maxIdleTime) Sets time to live and max idle time of specified entry by key.reactor.core.publisher.Mono
<Boolean> Stores value mapped by key with specified time to live.reactor.core.publisher.Mono
<Boolean> Stores value mapped by key with specified time to live and max idle time.reactor.core.publisher.Mono
<Boolean> fastPutIfAbsent
(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit) If the specified key is not already associated with a value, associate it with the given value.getAllWithTTLOnly
(Set<K> keys) Returns map slice contained the mappings with definedkeys
.reactor.core.publisher.Mono
<V> getWithTTLOnly
(K key) Returns the value mapped by definedkey
ornull
if value is absent.reactor.core.publisher.Mono
<V> Stores value mapped by key with specified time to live.reactor.core.publisher.Mono
<V> Stores value mapped by key with specified time to live and max idle time.reactor.core.publisher.Mono
<Void> Associates the specifiedvalue
with the specifiedkey
in batch.reactor.core.publisher.Mono
<V> putIfAbsent
(K key, V value, long ttl, TimeUnit unit) If the specified key is not already associated with a value, associate it with the given value.reactor.core.publisher.Mono
<V> putIfAbsent
(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit) If the specified key is not already associated with a value, associate it with the given value.reactor.core.publisher.Mono
<Long> remainTimeToLive
(K key) Remaining time to live of map entry associated with akey
.reactor.core.publisher.Mono
<Void> setMaxSize
(int maxSize) Sets max size of the map.reactor.core.publisher.Mono
<Void> setMaxSize
(int maxSize, EvictionMode mode) Sets max size of the map and overrides current value.reactor.core.publisher.Mono
<Integer> size()
Returns the number of entries in cache.reactor.core.publisher.Mono
<Boolean> trySetMaxSize
(int maxSize) Tries to set max size of the map.reactor.core.publisher.Mono
<Boolean> trySetMaxSize
(int maxSize, EvictionMode mode) Tries to set max size of the map.reactor.core.publisher.Mono
<Boolean> updateEntryExpiration
(K key, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit) Deprecated.Methods inherited from interface org.redisson.api.RDestroyable
destroy
Methods inherited from interface org.redisson.api.RExpirableReactive
clearExpire, expire, expire, expire, expireAt, expireAt, expireIfGreater, expireIfGreater, expireIfLess, expireIfLess, expireIfNotSet, expireIfNotSet, expireIfSet, expireIfSet, getExpireTime, remainTimeToLive
Methods inherited from interface org.redisson.api.RMapReactive
addAndGet, addListener, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entryIterator, entryIterator, entryIterator, entryIterator, fastPut, fastPutIfAbsent, fastPutIfExists, fastRemove, get, getAll, getFairLock, getLock, getPermitExpirableSemaphore, getReadWriteLock, getSemaphore, keyIterator, keyIterator, keyIterator, keyIterator, loadAll, loadAll, merge, put, putAll, putIfAbsent, putIfExists, randomEntries, randomKeys, readAllEntrySet, readAllKeySet, readAllMap, readAllValues, remove, remove, replace, replace, valueIterator, valueIterator, valueIterator, valueIterator, valueSize
Methods inherited from interface org.redisson.api.RObjectReactive
copy, copy, copy, copyAndReplace, copyAndReplace, delete, dump, getCodec, getIdleTime, getName, isExists, migrate, move, removeListener, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, sizeInMemory, touch, unlink
-
Method Details
-
setMaxSize
Sets max size of the map. Superfluous elements are evicted using LRU algorithm.- Parameters:
maxSize
- - max size- Returns:
- void
-
setMaxSize
Sets max size of the map and overrides current value. Superfluous elements are evicted using defined algorithm.- Parameters:
maxSize
- - max sizemode
- - eviction mode
-
trySetMaxSize
Tries to set max size of the map. Superfluous elements are evicted using LRU algorithm.- Parameters:
maxSize
- - max size- Returns:
true
if max size has been successfully set, otherwisefalse
.
-
trySetMaxSize
Tries to set max size of the map. Superfluous elements are evicted using defined algorithm.- Parameters:
maxSize
- - max sizemode
- - eviction mode- Returns:
true
if max size has been successfully set, otherwisefalse
.
-
putIfAbsent
If the specified key is not already associated with a value, associate it with the given value.Stores value mapped by key with specified time to live. Entry expires after specified time to live. If the map previously contained a mapping for the key, the old value is replaced by the specified value.
- Parameters:
key
- - map keyvalue
- - map valuettl
- - time to live for key\value entry. If0
then stores infinitely.unit
- - time unit- Returns:
- previous associated value
-
putIfAbsent
reactor.core.publisher.Mono<V> putIfAbsent(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit) If the specified key is not already associated with a value, associate it with the given value.Stores value mapped by key with specified time to live and max idle time. Entry expires when specified time to live or max idle time has expired.
If the map previously contained a mapping for the key, the old value is replaced by the specified value.
- Parameters:
key
- - map keyvalue
- - map valuettl
- - time to live for key\value entry. If0
then time to live doesn't affect entry expiration.ttlUnit
- - time unitmaxIdleTime
- - max idle time for key\value entry. If0
then max idle time doesn't affect entry expiration.maxIdleUnit
- - time unitif
maxIdleTime
andttl
params are equal to0
then entry stores infinitely.- Returns:
- previous associated value
-
computeIfAbsentAsync
reactor.core.publisher.Mono<V> computeIfAbsentAsync(K key, Duration ttl, Function<? super K, ? extends V> mappingFunction) If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map .Stores value mapped by key with specified time to live. Entry expires after specified time to live.
- Parameters:
key
- - map keyttl
- - time to live for key\value entry. If0
then stores infinitely.mappingFunction
- the mapping function to compute a value- Returns:
- current associated value
-
put
Stores value mapped by key with specified time to live. Entry expires after specified time to live. If the map previously contained a mapping for the key, the old value is replaced by the specified value.- Parameters:
key
- - map keyvalue
- - map valuettl
- - time to live for key\value entry. If0
then stores infinitely.unit
- - time unit- Returns:
- previous associated value
-
put
reactor.core.publisher.Mono<V> put(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit) Stores value mapped by key with specified time to live and max idle time. Entry expires when specified time to live or max idle time has expired.If the map previously contained a mapping for the key, the old value is replaced by the specified value.
- Parameters:
key
- - map keyvalue
- - map valuettl
- - time to live for key\value entry. If0
then time to live doesn't affect entry expiration.ttlUnit
- - time unitmaxIdleTime
- - max idle time for key\value entry. If0
then max idle time doesn't affect entry expiration.maxIdleUnit
- - time unitif
maxIdleTime
andttl
params are equal to0
then entry stores infinitely.- Returns:
- previous associated value
-
putAll
reactor.core.publisher.Mono<Void> putAll(Map<? extends K, ? extends V> map, long ttl, TimeUnit ttlUnit) Associates the specifiedvalue
with the specifiedkey
in batch.If
MapWriter
is defined then new map entries will be stored in write-through mode.- Parameters:
map
- - mappings to be stored in this mapttl
- - time to live for all key\value entries. If0
then stores infinitely.ttlUnit
- - time unit
-
fastPut
Stores value mapped by key with specified time to live. Entry expires after specified time to live.If the map previously contained a mapping for the key, the old value is replaced by the specified value.
Works faster than usual
put(Object, Object, long, TimeUnit)
as it not returns previous value.- Parameters:
key
- - map keyvalue
- - map valuettl
- - time to live for key\value entry. If0
then stores infinitely.unit
- - time unit- Returns:
true
if key is a new key in the hash and value was set.false
if key already exists in the hash and the value was updated.
-
fastPut
reactor.core.publisher.Mono<Boolean> fastPut(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit) Stores value mapped by key with specified time to live and max idle time. Entry expires when specified time to live or max idle time has expired.If the map previously contained a mapping for the key, the old value is replaced by the specified value.
Works faster than usual
put(Object, Object, long, TimeUnit, long, TimeUnit)
as it not returns previous value.- Parameters:
key
- - map keyvalue
- - map valuettl
- - time to live for key\value entry. If0
then time to live doesn't affect entry expiration.ttlUnit
- - time unitmaxIdleTime
- - max idle time for key\value entry. If0
then max idle time doesn't affect entry expiration.maxIdleUnit
- - time unitif
maxIdleTime
andttl
params are equal to0
then entry stores infinitely.- Returns:
true
if key is a new key in the hash and value was set.false
if key already exists in the hash and the value was updated.
-
fastPutIfAbsent
reactor.core.publisher.Mono<Boolean> fastPutIfAbsent(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit) If the specified key is not already associated with a value, associate it with the given value.Stores value mapped by key with specified time to live and max idle time. Entry expires when specified time to live or max idle time has expired.
Works faster than usual
putIfAbsent(Object, Object, long, TimeUnit, long, TimeUnit)
as it not returns previous value.- Parameters:
key
- - map keyvalue
- - map valuettl
- - time to live for key\value entry. If0
then time to live doesn't affect entry expiration.ttlUnit
- - time unitmaxIdleTime
- - max idle time for key\value entry. If0
then max idle time doesn't affect entry expiration.maxIdleUnit
- - time unitif
maxIdleTime
andttl
params are equal to0
then entry stores infinitely.- Returns:
true
if key is a new key in the hash and value was set.false
if key already exists in the hash
-
updateEntryExpiration
@Deprecated reactor.core.publisher.Mono<Boolean> updateEntryExpiration(K key, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit) Deprecated.UseexpireEntry(Object, Duration, Duration)
instead.- Parameters:
key
- - map keyttl
- - time to live for key\value entry. If0
then time to live doesn't affect entry expiration.ttlUnit
- - time unitmaxIdleTime
- - max idle time for key\value entry. If0
then max idle time doesn't affect entry expiration.maxIdleUnit
- - time unitif
maxIdleTime
andttl
params are equal to0
then entry stores infinitely.- Returns:
- returns
false
if entry already expired or doesn't exist, otherwise returnstrue
.
-
expireEntry
Updates time to live and max idle time of specified entry by key. Entry expires when specified time to live or max idle time was reached.Returns
false
if entry already expired or doesn't exist, otherwise returnstrue
.- Parameters:
key
- map keyttl
- time to live for key\value entry. If0
then time to live doesn't affect entry expiration.maxIdleTime
- max idle time for key\value entry. If0
then max idle time doesn't affect entry expiration.if
maxIdleTime
andttl
params are equal to0
then entry stores infinitely.- Returns:
- returns
false
if entry already expired or doesn't exist, otherwise returnstrue
.
-
expireEntries
Updates time to live and max idle time of specified entries by keys. Entries expires when specified time to live or max idle time was reached.Returns amount of updated entries.
- Parameters:
keys
- map keysttl
- time to live for key\value entries. If0
then time to live doesn't affect entry expiration.maxIdleTime
- max idle time for key\value entries. If0
then max idle time doesn't affect entry expiration.if
maxIdleTime
andttl
params are equal to0
then entries are stored infinitely.- Returns:
- amount of updated entries.
-
expireEntryIfNotSet
Sets time to live and max idle time of specified entry by key. If these parameters weren't set before. Entry expires when specified time to live or max idle time was reached.Returns
false
if entry already has expiration time or doesn't exist, otherwise returnstrue
.- Parameters:
key
- map keyttl
- time to live for key\value entry. If0
then time to live doesn't affect entry expiration.maxIdleTime
- max idle time for key\value entry. If0
then max idle time doesn't affect entry expiration.if
maxIdleTime
andttl
params are equal to0
then entry stores infinitely.- Returns:
- returns
false
if entry already has expiration time or doesn't exist, otherwise returnstrue
.
-
expireEntriesIfNotSet
reactor.core.publisher.Mono<Integer> expireEntriesIfNotSet(Set<K> keys, Duration ttl, Duration maxIdleTime) Sets time to live and max idle time of specified entries by keys. If these parameters weren't set before. Entries expire when specified time to live or max idle time was reached.Returns amount of updated entries.
- Parameters:
keys
- map keysttl
- time to live for key\value entry. If0
then time to live doesn't affect entry expiration.maxIdleTime
- max idle time for key\value entry. If0
then max idle time doesn't affect entry expiration.if
maxIdleTime
andttl
params are equal to0
then entry stores infinitely.- Returns:
- amount of updated entries.
-
getWithTTLOnly
Returns the value mapped by definedkey
ornull
if value is absent.If map doesn't contain value for specified key and
MapLoader
is defined then value will be loaded in read-through mode.Idle time of entry is not taken into account. Entry last access time isn't modified if map limited by size.
- Parameters:
key
- the key- Returns:
- the value mapped by defined
key
ornull
if value is absent
-
getAllWithTTLOnly
Returns map slice contained the mappings with definedkeys
.If map doesn't contain value/values for specified key/keys and
MapLoader
is defined then value/values will be loaded in read-through mode.NOTE: Idle time of entry is not taken into account. Entry last access time isn't modified if map limited by size.
- Parameters:
keys
- map keys- Returns:
- Map slice
-
size
reactor.core.publisher.Mono<Integer> size()Returns the number of entries in cache. This number can reflects expired entries too due to non realtime cleanup process.- Specified by:
size
in interfaceRMapReactive<K,
V> - Returns:
- size
-
remainTimeToLive
Remaining time to live of map entry associated with akey
.- Parameters:
key
- - map key- Returns:
- time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
-
addListener
Adds map entry listener- Parameters:
listener
- - entry listener- Returns:
- listener id
- See Also:
-