public class RedisCacheConfiguration extends Object
RedisCacheConfiguration
helps customizing RedisCache
behaviour such as caching
null values, cache key prefixes and binary serialization. defaultCacheConfig()
and customize RedisCache
behaviour from there
on.Modifier and Type | Method and Description |
---|---|
static RedisCacheConfiguration |
defaultCacheConfig()
Default
RedisCacheConfiguration using the following:
key expiration
eternal
cache null values
yes
prefix cache keys
yes
default prefix
[the actual cache name]
key serializer
StringRedisSerializer.class
value serializer
JdkSerializationRedisSerializer.class
conversion service
DefaultFormattingConversionService with default
cache key converters
|
RedisCacheConfiguration |
disableCachingNullValues()
Disable caching null values.
|
RedisCacheConfiguration |
disableKeyPrefix()
Disable using cache key prefixes.
|
RedisCacheConfiguration |
entryTtl(Duration ttl)
Set the ttl to apply for cache entries.
|
boolean |
getAllowCacheNullValues() |
org.springframework.core.convert.ConversionService |
getConversionService() |
Optional<String> |
getKeyPrefix() |
RedisSerializationContext.SerializationPair<String> |
getKeySerializationPair() |
Duration |
getTtl() |
RedisSerializationContext.SerializationPair<Object> |
getValueSerializationPair() |
RedisCacheConfiguration |
prefixKeysWith(String prefix)
Use the given prefix instead of the default one.
|
static void |
registerDefaultConverters(org.springframework.core.convert.converter.ConverterRegistry registry)
Registers default cache key converters.
|
RedisCacheConfiguration |
serializeKeysWith(RedisSerializationContext.SerializationPair<String> keySerializationPair)
Define the
RedisSerializationContext.SerializationPair used for de-/serializing cache keys. |
RedisCacheConfiguration |
serializeValuesWith(RedisSerializationContext.SerializationPair<?> valueSerializationPair)
Define the
RedisSerializationContext.SerializationPair used for de-/serializing cache values. |
boolean |
usePrefix() |
RedisCacheConfiguration |
withConversionService(org.springframework.core.convert.ConversionService conversionService)
Define the
ConversionService used for cache key to String conversion. |
public static RedisCacheConfiguration defaultCacheConfig()
RedisCacheConfiguration
using the following:
DefaultFormattingConversionService
with default
cache key convertersRedisCacheConfiguration
.public RedisCacheConfiguration entryTtl(Duration ttl)
Duration.ZERO
to declare an eternal cache.ttl
- must not be null.RedisCacheConfiguration
.public RedisCacheConfiguration prefixKeysWith(String prefix)
prefix
- must not be null.RedisCacheConfiguration
.public RedisCacheConfiguration disableCachingNullValues()
Cache.put(Object, Object)
operation involving
null value will error. Nothing will be written to Redis, nothing will be removed. An already existing
key will still be there afterwards with the very same value as before.RedisCacheConfiguration
.public RedisCacheConfiguration disableKeyPrefix()
Cache.clear()
might result in unintended removal of keys in Redis. Make
sure to use a dedicated Redis instance when disabling prefixes.RedisCacheConfiguration
.public RedisCacheConfiguration withConversionService(org.springframework.core.convert.ConversionService conversionService)
ConversionService
used for cache key to String
conversion.conversionService
- must not be null.RedisCacheConfiguration
.public RedisCacheConfiguration serializeKeysWith(RedisSerializationContext.SerializationPair<String> keySerializationPair)
RedisSerializationContext.SerializationPair
used for de-/serializing cache keys.keySerializationPair
- must not be null.RedisCacheConfiguration
.public RedisCacheConfiguration serializeValuesWith(RedisSerializationContext.SerializationPair<?> valueSerializationPair)
RedisSerializationContext.SerializationPair
used for de-/serializing cache values.valueSerializationPair
- must not be null.RedisCacheConfiguration
.public boolean usePrefix()
getKeyPrefix()
if present or the
default which resolves to Cache.getName()
.public boolean getAllowCacheNullValues()
public RedisSerializationContext.SerializationPair<String> getKeySerializationPair()
public RedisSerializationContext.SerializationPair<Object> getValueSerializationPair()
public Duration getTtl()
public org.springframework.core.convert.ConversionService getConversionService()
ConversionService
used for cache key to String
conversion. Never null.public static void registerDefaultConverters(org.springframework.core.convert.converter.ConverterRegistry registry)
registry
- must not be null.Copyright © 2011–2017 Pivotal Software, Inc.. All rights reserved.