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
ConstructorsModifierConstructorDescriptionprotectedRedisCache(String name, RedisCacheWriter cacheWriter, RedisCacheConfiguration cacheConfig) Create newRedisCache. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()voidClear keys that match the providedkeyPattern.voidReset all statistics counters and gauges for this cache.protected StringconvertKey(Object key) Convertkeyto aStringrepresentation used for cache key creation.protected StringcreateCacheKey(Object key) Customization hook for creating cache key before it gets serialized.protected ObjectdeserializeCacheValue(byte[] value) Deserialize the given value to the actual cache value.void<T> TGetRedisCacheConfigurationused.getName()Return theCacheStatisticssnapshot for this cache instance.protected Objectprotected ObjectpreProcessCacheValue(Object value) Customization hook called before passing object toRedisSerializer.voidputIfAbsent(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, toValueWrapperMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
lookupin 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 theCacheStatisticssnapshot 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
GetRedisCacheConfigurationused.- 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
Convertkeyto aStringrepresentation used for cache key creation.- Parameters:
key- will never be null.- Returns:
- never null.
- Throws:
IllegalStateException- ifkeycannot be converted toString.
-