Class RedisCacheManager
java.lang.Object
org.springframework.cache.support.AbstractCacheManager
org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager
org.springframework.data.redis.cache.RedisCacheManager
- All Implemented Interfaces:
InitializingBean
,CacheManager
CacheManager
backed by a Redis
cache.
This cache manager creates caches by default upon first write. Empty caches are not visible on Redis due to how Redis represents empty data structures.
Caches requiring a different RedisCacheConfiguration
than the default configuration can be specified via
RedisCacheManager.RedisCacheManagerBuilder.withInitialCacheConfigurations(Map)
.
- Since:
- 2.0
- Author:
- Christoph Strobl, Mark Paluch
- See Also:
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionRedisCacheManager
(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) RedisCacheManager
(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, boolean allowInFlightCacheCreation, String... initialCacheNames) RedisCacheManager
(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, String... initialCacheNames) RedisCacheManager
(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, Map<String, RedisCacheConfiguration> initialCacheConfigurations) RedisCacheManager
(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, Map<String, RedisCacheConfiguration> initialCacheConfigurations, boolean allowInFlightCacheCreation) -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
Entry point for builder styleRedisCacheManager
configuration.builder
(RedisCacheWriter cacheWriter) Entry point for builder styleRedisCacheManager
configuration.builder
(RedisConnectionFactory connectionFactory) Entry point for builder styleRedisCacheManager
configuration.static RedisCacheManager
create
(RedisConnectionFactory connectionFactory) Create a newRedisCacheManager
with defaults applied.protected RedisCache
createRedisCache
(String name, RedisCacheConfiguration cacheConfig) Configuration hook for creatingRedisCache
with given name andcacheConfig
.protected RedisCache
getMissingCache
(String name) protected Collection<RedisCache>
Methods inherited from class org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager
decorateCache, isTransactionAware, setTransactionAware
Methods inherited from class org.springframework.cache.support.AbstractCacheManager
afterPropertiesSet, getCache, getCacheNames, initializeCaches, lookupCache
-
Constructor Details
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) - Parameters:
cacheWriter
- must not be null.defaultCacheConfiguration
- must not be null. Maybe just useRedisCacheConfiguration.defaultCacheConfig()
.
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, String... initialCacheNames) - Parameters:
cacheWriter
- must not be null.defaultCacheConfiguration
- must not be null. Maybe just useRedisCacheConfiguration.defaultCacheConfig()
.initialCacheNames
- optional set of known cache names that will be created with given defaultCacheConfiguration.
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, boolean allowInFlightCacheCreation, String... initialCacheNames) - Parameters:
cacheWriter
- must not be null.defaultCacheConfiguration
- must not be null. Maybe just useRedisCacheConfiguration.defaultCacheConfig()
.allowInFlightCacheCreation
- if set to true no new caches can be acquire at runtime but limited to the given list of initial cache names.initialCacheNames
- optional set of known cache names that will be created with given defaultCacheConfiguration.- Since:
- 2.0.4
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, Map<String, RedisCacheConfiguration> initialCacheConfigurations) - Parameters:
cacheWriter
- must not be null.defaultCacheConfiguration
- must not be null. Maybe just useRedisCacheConfiguration.defaultCacheConfig()
.initialCacheConfigurations
- Map of known cache names along with the configuration to use for those caches. Must not be null.
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, Map<String, RedisCacheConfiguration> initialCacheConfigurations, boolean allowInFlightCacheCreation) - Parameters:
cacheWriter
- must not be null.defaultCacheConfiguration
- must not be null. Maybe just useRedisCacheConfiguration.defaultCacheConfig()
.initialCacheConfigurations
- Map of known cache names along with the configuration to use for those caches. Must not be null.allowInFlightCacheCreation
- if set to false this cache manager is limited to the initial cache configurations and will not create new caches at runtime.- Since:
- 2.0.4
-
-
Method Details
-
create
Create a newRedisCacheManager
with defaults applied.- locking
- disabled
- batch strategy
BatchStrategies.keys()
- cache configuration
RedisCacheConfiguration.defaultCacheConfig()
- initial caches
- none
- transaction aware
- no
- in-flight cache creation
- enabled
- Parameters:
connectionFactory
- must not be null.- Returns:
- new instance of
RedisCacheManager
.
-
builder
Entry point for builder styleRedisCacheManager
configuration.- Returns:
- new
RedisCacheManager.RedisCacheManagerBuilder
. - Since:
- 2.3
-
builder
public static RedisCacheManager.RedisCacheManagerBuilder builder(RedisConnectionFactory connectionFactory) Entry point for builder styleRedisCacheManager
configuration.- Parameters:
connectionFactory
- must not be null.- Returns:
- new
RedisCacheManager.RedisCacheManagerBuilder
.
-
builder
Entry point for builder styleRedisCacheManager
configuration.- Parameters:
cacheWriter
- must not be null.- Returns:
- new
RedisCacheManager.RedisCacheManagerBuilder
.
-
loadCaches
- Specified by:
loadCaches
in classAbstractCacheManager
-
getMissingCache
- Overrides:
getMissingCache
in classAbstractCacheManager
-
getCacheConfigurations
- Returns:
- unmodifiable
Map
containing cache name / configuration pairs. Never null.
-
createRedisCache
Configuration hook for creatingRedisCache
with given name andcacheConfig
.- Parameters:
name
- must not be null.cacheConfig
- can be null.- Returns:
- never null.
-