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 |
|---|---|
void |
addCacheKeyConverter(Converter<?,String> cacheKeyConverter)
Add a
Converter for extracting the String representation of a cache key if no suitable
Object.toString() method is present. |
RedisCacheConfiguration |
computePrefixWith(CacheKeyPrefix cacheKeyPrefix)
Use the given
CacheKeyPrefix to compute the prefix for the actual Redis key on the
cache name. |
void |
configureKeyConverters(Consumer<ConverterRegistry> registryConsumer)
Configure the underlying conversion system used to extract the cache key.
|
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
value serializer
JdkSerializationRedisSerializer
conversion service
DefaultFormattingConversionService with default
cache key converters
|
static RedisCacheConfiguration |
defaultCacheConfig(ClassLoader classLoader)
Create default
RedisCacheConfiguration given ClassLoader using the following:
key expiration
eternal
cache null values
yes
prefix cache keys
yes
default prefix
[the actual cache name]
key serializer
StringRedisSerializer
value serializer
JdkSerializationRedisSerializer
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() |
ConversionService |
getConversionService() |
Optional<String> |
getKeyPrefix()
Deprecated.
since 2.0.4. Please use
getKeyPrefixFor(String). |
String |
getKeyPrefixFor(String cacheName)
Get the computed key prefix for a given cacheName.
|
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(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(ConversionService conversionService)
Define the
ConversionService used for cache key to String conversion. |
public static RedisCacheConfiguration defaultCacheConfig()
RedisCacheConfiguration using the following:
StringRedisSerializerJdkSerializationRedisSerializerDefaultFormattingConversionService with default
cache key convertersRedisCacheConfiguration.public static RedisCacheConfiguration defaultCacheConfig(@Nullable ClassLoader classLoader)
RedisCacheConfiguration given ClassLoader using the following:
StringRedisSerializerJdkSerializationRedisSerializerDefaultFormattingConversionService with default
cache key convertersclassLoader - the ClassLoader used for deserialization by the
JdkSerializationRedisSerializer.RedisCacheConfiguration.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 computePrefixWith(CacheKeyPrefix cacheKeyPrefix)
CacheKeyPrefix to compute the prefix for the actual Redis key on the
cache name.cacheKeyPrefix - 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(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.@Deprecated public Optional<String> getKeyPrefix()
getKeyPrefixFor(String).public String getKeyPrefixFor(String cacheName)
public boolean usePrefix()
getKeyPrefixFor(String) 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 ConversionService getConversionService()
ConversionService used for cache key to String conversion. Never null.public void addCacheKeyConverter(Converter<?,String> cacheKeyConverter)
Converter for extracting the String representation of a cache key if no suitable
Object.toString() method is present.cacheKeyConverter - IllegalStateException - if getConversionService() does not allow converter registration.public void configureKeyConverters(Consumer<ConverterRegistry> registryConsumer)
registryConsumer - never null.IllegalStateException - if getConversionService() does not allow converter registration.public static void registerDefaultConverters(ConverterRegistry registry)
registry - must not be null.Copyright © 2011–2019 Pivotal Software, Inc.. All rights reserved.