Interface RMapCache<K,V>
-
- Type Parameters:
K
- keyV
- value
- All Superinterfaces:
ConcurrentMap<K,V>
,Map<K,V>
,RDestroyable
,RExpirable
,RExpirableAsync
,RMap<K,V>
,RMapAsync<K,V>
,RMapCacheAsync<K,V>
,RObject
,RObjectAsync
- All Known Implementing Classes:
RedissonMapCache
,RedissonTransactionalMapCache
public interface RMapCache<K,V> extends RMap<K,V>, RMapCacheAsync<K,V>, RDestroyable
Map-based cache with ability to set TTL for each entry via
put(Object, Object, long, TimeUnit)
orputIfAbsent(Object, Object, long, TimeUnit)
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. Expired tasks cleaned by
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
RedissonMap
.- Author:
- Nikita Koksharov
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description int
addListener(MapEntryListener listener)
Adds map entry listenerboolean
fastPut(K key, V value, long ttl, TimeUnit ttlUnit)
Stores value mapped by key with specified time to live.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.boolean
fastPutIfAbsent(K key, V value, long ttl, TimeUnit ttlUnit)
If the specified key is not already associated with a value, associate it with the given value.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.V
getWithTTLOnly(K key)
Returns the value mapped by definedkey
ornull
if value is absent.V
put(K key, V value, long ttl, TimeUnit unit)
Stores value mapped by key with specified time to live.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.void
putAll(Map<? extends K,? extends V> map, long ttl, TimeUnit ttlUnit)
Associates the specifiedvalue
with the specifiedkey
in batch.V
putIfAbsent(K key, V value, long ttl, TimeUnit ttlUnit)
If the specified key is not already associated with a value, associate it with the given value.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.long
remainTimeToLive(K key)
Remaining time to live of map entry associated with akey
.void
removeListener(int listenerId)
Removes map entry listenervoid
setMaxSize(int maxSize)
Sets max size of the map and overrides current value.void
setMaxSize(int maxSize, EvictionMode mode)
Sets max size of the map and overrides current value.int
size()
Returns the number of entries in cache.boolean
trySetMaxSize(int maxSize)
Tries to set max size of the map.boolean
trySetMaxSize(int maxSize, EvictionMode mode)
Tries to set max size of the map.boolean
updateEntryExpiration(K key, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit)
Updates time to live and max idle time of specified entry by key.-
Methods inherited from interface java.util.concurrent.ConcurrentMap
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, replaceAll
-
Methods inherited from interface org.redisson.api.RDestroyable
destroy
-
Methods inherited from interface org.redisson.api.RExpirable
clearExpire, expire, expire, expireAt, expireAt, remainTimeToLive
-
Methods inherited from interface org.redisson.api.RExpirableAsync
clearExpireAsync, expireAsync, expireAsync, expireAtAsync, expireAtAsync, remainTimeToLiveAsync
-
Methods inherited from interface org.redisson.api.RMap
addAndGet, containsKey, containsValue, entrySet, entrySet, entrySet, entrySet, fastPut, fastPutIfAbsent, fastPutIfExists, fastRemove, fastReplace, get, getAll, getCountDownLatch, getFairLock, getLock, getPermitExpirableSemaphore, getReadWriteLock, getSemaphore, keySet, keySet, keySet, keySet, loadAll, loadAll, mapReduce, put, putAll, putAll, putIfAbsent, putIfExists, randomEntries, randomKeys, readAllEntrySet, readAllKeySet, readAllMap, readAllValues, remove, remove, replace, replace, values, values, values, values, valueSize
-
Methods inherited from interface org.redisson.api.RMapAsync
addAndGetAsync, computeAsync, computeIfAbsentAsync, computeIfPresentAsync, containsKeyAsync, containsValueAsync, fastPutAsync, fastPutIfAbsentAsync, fastPutIfExistsAsync, fastRemoveAsync, fastReplaceAsync, getAllAsync, getAsync, loadAllAsync, loadAllAsync, mergeAsync, putAllAsync, putAllAsync, putAsync, putIfAbsentAsync, putIfExistsAsync, randomEntriesAsync, randomKeysAsync, readAllEntrySetAsync, readAllKeySetAsync, readAllMapAsync, readAllValuesAsync, removeAsync, removeAsync, replaceAsync, replaceAsync, valueSizeAsync
-
Methods inherited from interface org.redisson.api.RMapCacheAsync
fastPutAsync, fastPutAsync, fastPutIfAbsentAsync, getWithTTLOnlyAsync, putAllAsync, putAsync, putAsync, putIfAbsentAsync, putIfAbsentAsync, remainTimeToLiveAsync, setMaxSizeAsync, setMaxSizeAsync, sizeAsync, trySetMaxSizeAsync, trySetMaxSizeAsync, updateEntryExpirationAsync
-
Methods inherited from interface org.redisson.api.RObject
addListener, copy, delete, dump, getCodec, getIdleTime, getName, isExists, migrate, move, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, sizeInMemory, touch, unlink
-
Methods inherited from interface org.redisson.api.RObjectAsync
addListenerAsync, copyAsync, deleteAsync, dumpAsync, getIdleTimeAsync, isExistsAsync, migrateAsync, moveAsync, removeListenerAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemoryAsync, touchAsync, unlinkAsync
-
-
-
-
Method Detail
-
setMaxSize
void setMaxSize(int maxSize)
Sets max size of the map and overrides current value. Superfluous elements are evicted using LRU algorithm.- Parameters:
maxSize
- - max size If0
the cache is unbounded (default).
-
setMaxSize
void setMaxSize(int maxSize, EvictionMode mode)
Sets max size of the map and overrides current value. Superfluous elements are evicted using defined algorithm.- Parameters:
maxSize
- - max sizemode
- - eviction mode
-
trySetMaxSize
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
. If0
the cache is unbounded (default).
-
trySetMaxSize
boolean trySetMaxSize(int maxSize, EvictionMode mode)
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
V putIfAbsent(K key, V value, long ttl, TimeUnit ttlUnit)
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.
- Parameters:
key
- - map keyvalue
- - map valuettl
- - time to live for key\value entry. If0
then stores infinitely.ttlUnit
- - time unit- Returns:
- current associated value
-
putIfAbsent
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.
- 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:
- current associated value
-
put
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
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
boolean fastPut(K key, V value, long ttl, TimeUnit ttlUnit)
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.ttlUnit
- - 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
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
boolean fastPutIfAbsent(K key, V value, long ttl, TimeUnit ttlUnit)
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.
Works faster than usual
putIfAbsent(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.ttlUnit
- - 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
-
fastPutIfAbsent
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.
-
putAll
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
-
updateEntryExpiration
boolean updateEntryExpiration(K key, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit)
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.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
.
-
getWithTTLOnly
V getWithTTLOnly(K key)
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
-
size
int size()
Returns the number of entries in cache. This number can reflects expired entries too due to non realtime cleanup process.
-
addListener
int addListener(MapEntryListener listener)
Adds map entry listener- Parameters:
listener
- - entry listener- Returns:
- listener id
- See Also:
EntryCreatedListener
,EntryUpdatedListener
,EntryRemovedListener
,EntryExpiredListener
-
removeListener
void removeListener(int listenerId)
Removes map entry listener- Specified by:
removeListener
in interfaceRObject
- Parameters:
listenerId
- - listener id
-
remainTimeToLive
long remainTimeToLive(K key)
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.
-
-