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
Map-based cache with ability to set TTL for each entry via
put(Object, Object, long, TimeUnit) or putIfAbsent(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
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionintaddListener(MapEntryListener listener) Adds map entry listenerbooleanStores value mapped by key with specified time to live.booleanStores value mapped by key with specified time to live and max idle time.booleanfastPutIfAbsent(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.booleanfastPutIfAbsent(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.getWithTTLOnly(K key) Returns the value mapped by definedkeyornullif value is absent.Stores value mapped by key with specified time to live.Stores value mapped by key with specified time to live and max idle time.voidAssociates the specifiedvaluewith the specifiedkeyin batch.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.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.longremainTimeToLive(K key) Remaining time to live of map entry associated with akey.voidremoveListener(int listenerId) Removes map entry listenervoidsetMaxSize(int maxSize) Sets max size of the map and overrides current value.voidsetMaxSize(int maxSize, EvictionMode mode) Sets max size of the map and overrides current value.intsize()Returns the number of entries in cache.booleantrySetMaxSize(int maxSize) Tries to set max size of the map.booleantrySetMaxSize(int maxSize, EvictionMode mode) Tries to set max size of the map.booleanupdateEntryExpiration(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, replaceAllMethods inherited from interface org.redisson.api.RDestroyable
destroyMethods inherited from interface org.redisson.api.RExpirable
clearExpire, expire, expire, expire, expireAt, expireAt, expireIfGreater, expireIfGreater, expireIfLess, expireIfLess, expireIfNotSet, expireIfNotSet, expireIfSet, expireIfSet, getExpireTime, remainTimeToLiveMethods inherited from interface org.redisson.api.RExpirableAsync
clearExpireAsync, expireAsync, expireAsync, expireAsync, expireAtAsync, expireAtAsync, expireIfGreaterAsync, expireIfGreaterAsync, expireIfLessAsync, expireIfLessAsync, expireIfNotSetAsync, expireIfNotSetAsync, expireIfSetAsync, expireIfSetAsync, getExpireTimeAsync, remainTimeToLiveAsyncMethods 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, valueSizeMethods 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, valueSizeAsyncMethods inherited from interface org.redisson.api.RMapCacheAsync
fastPutAsync, fastPutAsync, fastPutIfAbsentAsync, getWithTTLOnlyAsync, putAllAsync, putAsync, putAsync, putIfAbsentAsync, putIfAbsentAsync, remainTimeToLiveAsync, setMaxSizeAsync, setMaxSizeAsync, sizeAsync, trySetMaxSizeAsync, trySetMaxSizeAsync, updateEntryExpirationAsyncMethods 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, unlinkMethods 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 Details
-
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 If0the cache is unbounded (default).
-
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
boolean trySetMaxSize(int maxSize) Tries to set max size of the map. Superfluous elements are evicted using LRU algorithm.- Parameters:
maxSize- - max size- Returns:
trueif max size has been successfully set, otherwisefalse. If0the cache is unbounded (default).
-
trySetMaxSize
Tries to set max size of the map. Superfluous elements are evicted using defined algorithm.- Parameters:
maxSize- - max sizemode- - eviction mode- Returns:
trueif 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.
- Parameters:
key- - map keyvalue- - map valuettl- - time to live for key\value entry. If0then stores infinitely.ttlUnit- - time unit- Returns:
- current associated value
-
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 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. If0then time to live doesn't affect entry expiration.ttlUnit- - time unitmaxIdleTime- - max idle time for key\value entry. If0then max idle time doesn't affect entry expiration.maxIdleUnit- - time unitif
maxIdleTimeandttlparams are equal to0then entry stores infinitely.- 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. If0then stores infinitely.unit- - time unit- Returns:
- previous associated value
-
put
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. If0then time to live doesn't affect entry expiration.ttlUnit- - time unitmaxIdleTime- - max idle time for key\value entry. If0then max idle time doesn't affect entry expiration.maxIdleUnit- - time unitif
maxIdleTimeandttlparams are equal to0then entry stores infinitely.- Returns:
- previous associated value
-
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. If0then stores infinitely.ttlUnit- - time unit- Returns:
trueif key is a new key in the hash and value was set.falseif key already exists in the hash and the value was updated.
-
fastPut
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. If0then time to live doesn't affect entry expiration.ttlUnit- - time unitmaxIdleTime- - max idle time for key\value entry. If0then max idle time doesn't affect entry expiration.maxIdleUnit- - time unitif
maxIdleTimeandttlparams are equal to0then entry stores infinitely.- Returns:
trueif key is a new key in the hash and value was set.falseif key already exists in the hash and the value was updated.
-
fastPutIfAbsent
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. If0then stores infinitely.ttlUnit- - time unit- Returns:
trueif key is a new key in the hash and value was set.falseif 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. If0then time to live doesn't affect entry expiration.ttlUnit- - time unitmaxIdleTime- - max idle time for key\value entry. If0then max idle time doesn't affect entry expiration.maxIdleUnit- - time unitif
maxIdleTimeandttlparams are equal to0then entry stores infinitely.- Returns:
trueif key is a new key in the hash and value was set.falseif key already exists in the hash.
-
putAll
Associates the specifiedvaluewith the specifiedkeyin batch.If
MapWriteris 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. If0then 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
falseif entry already expired or doesn't exist, otherwise returnstrue.- Parameters:
key- - map keyttl- - time to live for key\value entry. If0then time to live doesn't affect entry expiration.ttlUnit- - time unitmaxIdleTime- - max idle time for key\value entry. If0then max idle time doesn't affect entry expiration.maxIdleUnit- - time unitif
maxIdleTimeandttlparams are equal to0then entry stores infinitely.- Returns:
- returns
falseif entry already expired or doesn't exist, otherwise returnstrue.
-
getWithTTLOnly
Returns the value mapped by definedkeyornullif value is absent.If map doesn't contain value for specified key and
MapLoaderis 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
keyornullif 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
Adds map entry listener- Parameters:
listener- - entry listener- Returns:
- listener id
- See Also:
-
removeListener
void removeListener(int listenerId) Removes map entry listener- Specified by:
removeListenerin interfaceRObject- Parameters:
listenerId- - listener id
-
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.
-