Class RedisCache
java.lang.Object
org.springframework.cache.support.AbstractValueAdaptingCache
org.springframework.data.redis.cache.RedisCache
- All Implemented Interfaces:
Cache
Cache
implementation using for Redis as underlying store.
Use RedisCacheManager
to create RedisCache
instances.
- Since:
- 2.0
- Author:
- Christoph Strobl, Mark Paluch, Piotr Mionskowski, Jos Roseboom
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.cache.Cache
Cache.ValueRetrievalException, Cache.ValueWrapper
-
Constructor Summary
ModifierConstructorDescriptionprotected
RedisCache
(String name, RedisCacheWriter cacheWriter, RedisCacheConfiguration cacheConfig) Create newRedisCache
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
void
Clear keys that match the providedkeyPattern
.void
Reset all statistics counters and gauges for this cache.protected String
convertKey
(Object key) Convertkey
to aString
representation used for cache key creation.protected String
createCacheKey
(Object key) Customization hook for creating cache key before it gets serialized.protected Object
deserializeCacheValue
(byte[] value) Deserialize the given value to the actual cache value.void
<T> T
GetRedisCacheConfiguration
used.getName()
Return theCacheStatistics
snapshot for this cache instance.protected Object
protected Object
preProcessCacheValue
(Object value) Customization hook called before passing object toRedisSerializer
.void
putIfAbsent
(Object key, Object value) protected byte[]
serializeCacheKey
(String cacheKey) Serialize the key.protected byte[]
serializeCacheValue
(Object value) Serialize the value to cache.Methods inherited from class org.springframework.cache.support.AbstractValueAdaptingCache
fromStoreValue, get, get, isAllowNullValues, toStoreValue, toValueWrapper
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.cache.Cache
evictIfPresent, invalidate
-
Constructor Details
-
RedisCache
protected RedisCache(String name, RedisCacheWriter cacheWriter, RedisCacheConfiguration cacheConfig) Create newRedisCache
.- Parameters:
name
- must not be null.cacheWriter
- must not be null.cacheConfig
- must not be null.
-
-
Method Details
-
lookup
- Specified by:
lookup
in classAbstractValueAdaptingCache
-
getName
-
getNativeCache
-
get
-
put
-
putIfAbsent
-
evict
-
clear
public void clear() -
clear
Clear keys that match the providedkeyPattern
.Useful when cache keys are formatted in a style where Redis patterns can be used for matching these.
- Parameters:
keyPattern
- the pattern of the key- Since:
- 3.0
-
getStatistics
Return theCacheStatistics
snapshot for this cache instance. Statistics are accumulated per cache instance and not from the backing Redis data store.- Returns:
- statistics object for this
RedisCache
. - Since:
- 2.4
-
clearStatistics
public void clearStatistics()Reset all statistics counters and gauges for this cache.- Since:
- 2.4
-
getCacheConfiguration
GetRedisCacheConfiguration
used.- Returns:
- immutable
RedisCacheConfiguration
. Never null.
-
preProcessCacheValue
Customization hook called before passing object toRedisSerializer
.- Parameters:
value
- can be null.- Returns:
- preprocessed value. Can be null.
-
serializeCacheKey
Serialize the key.- Parameters:
cacheKey
- must not be null.- Returns:
- never null.
-
serializeCacheValue
Serialize the value to cache.- Parameters:
value
- must not be null.- Returns:
- never null.
-
deserializeCacheValue
Deserialize the given value to the actual cache value.- Parameters:
value
- must not be null.- Returns:
- can be null.
-
createCacheKey
Customization hook for creating cache key before it gets serialized.- Parameters:
key
- will never be null.- Returns:
- never null.
-
convertKey
Convertkey
to aString
representation used for cache key creation.- Parameters:
key
- will never be null.- Returns:
- never null.
- Throws:
IllegalStateException
- ifkey
cannot be converted toString
.
-