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 intaddListener(MapEntryListener listener)Adds map entry listenerbooleanfastPut(K key, V value, long ttl, TimeUnit ttlUnit)Stores value mapped by key with specified time to live.booleanfastPut(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.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.VgetWithTTLOnly(K key)Returns the value mapped by definedkeyornullif value is absent.Vput(K key, V value, long ttl, TimeUnit unit)Stores value mapped by key with specified time to live.Vput(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.voidputAll(Map<? extends K,? extends V> map, long ttl, TimeUnit ttlUnit)Associates the specifiedvaluewith the specifiedkeyin batch.VputIfAbsent(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.VputIfAbsent(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, 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 If0the 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:
trueif max size has been successfully set, otherwisefalse. If0the 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:
trueif 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. If0then 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. 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
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. If0then 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. 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
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. 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
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. 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
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. 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
void putAll(Map<? extends K,? extends V> map, long ttl, TimeUnit ttlUnit)
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
V getWithTTLOnly(K key)
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
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:
removeListenerin 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.
-
-