Interface RMapCacheReactive<K,V>
-
- Type Parameters:
K
- keyV
- value
- All Superinterfaces:
RExpirableReactive
,RMapReactive<K,V>
,RObjectReactive
public interface RMapCacheReactive<K,V> extends RMapReactive<K,V>
Map-based cache with ability to set TTL for each entry via
put(Object, Object, long, TimeUnit)
orputIfAbsent(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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description org.reactivestreams.Publisher<Boolean>
fastPut(K key, V value, long ttl, TimeUnit unit)
Stores value mapped by key with specified time to live.org.reactivestreams.Publisher<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.org.reactivestreams.Publisher<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.org.reactivestreams.Publisher<V>
put(K key, V value, long ttl, TimeUnit unit)
Stores value mapped by key with specified time to live.org.reactivestreams.Publisher<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.org.reactivestreams.Publisher<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.org.reactivestreams.Publisher<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.org.reactivestreams.Publisher<Long>
remainTimeToLive(K key)
Remaining time to live of map entry associated with akey
.org.reactivestreams.Publisher<Void>
setMaxSize(int maxSize)
Sets max size of the map.org.reactivestreams.Publisher<Integer>
size()
Returns the number of entries in cache.org.reactivestreams.Publisher<Boolean>
trySetMaxSize(int maxSize)
Tries to set max size of the map.-
Methods inherited from interface org.redisson.api.RExpirableReactive
clearExpire, expire, expireAt, expireAt, remainTimeToLive
-
Methods inherited from interface org.redisson.api.RMapReactive
addAndGet, containsKey, containsValue, entryIterator, entryIterator, entryIterator, entryIterator, fastPut, fastPutIfAbsent, fastRemove, get, getAll, keyIterator, keyIterator, keyIterator, keyIterator, loadAll, loadAll, put, putAll, putIfAbsent, readAllEntrySet, readAllKeySet, readAllMap, readAllValues, remove, remove, replace, replace, valueIterator, valueIterator, valueIterator, valueIterator, valueSize
-
-
-
-
Method Detail
-
setMaxSize
org.reactivestreams.Publisher<Void> setMaxSize(int maxSize)
Sets max size of the map. Superfluous elements are evicted using LRU algorithm.- Parameters:
maxSize
- - max size- Returns:
- void
-
trySetMaxSize
org.reactivestreams.Publisher<Boolean> trySetMaxSize(int maxSize)
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
.
-
putIfAbsent
org.reactivestreams.Publisher<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.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
org.reactivestreams.Publisher<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
-
put
org.reactivestreams.Publisher<V> put(K key, V value, long ttl, TimeUnit unit)
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
org.reactivestreams.Publisher<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
-
fastPut
org.reactivestreams.Publisher<Boolean> fastPut(K key, V value, long ttl, TimeUnit unit)
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
org.reactivestreams.Publisher<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
org.reactivestreams.Publisher<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
-
size
org.reactivestreams.Publisher<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>
-
-