Class RedisCacheManager
java.lang.Object
org.springframework.cache.support.AbstractCacheManager
org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager
org.springframework.data.redis.cache.RedisCacheManager
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean,org.springframework.cache.CacheManager
public class RedisCacheManager
extends org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager
CacheManager backed by a RedisCache.
This CacheManager creates caches by default upon first write. Empty caches
are not visible in Redis due to how Redis represents empty data structures.
Caches requiring a different RedisCacheConfiguration than the default cache configuration
can be specified via RedisCacheManager.RedisCacheManagerBuilder.withInitialCacheConfigurations(Map) or individually
using RedisCacheManager.RedisCacheManagerBuilder.withCacheConfiguration(String, RedisCacheConfiguration).
- Since:
- 2.0
- Author:
- Christoph Strobl, Mark Paluch, Yanming Zhou, John Blum
- See Also:
-
AbstractTransactionSupportingCacheManagerRedisCacheConfigurationRedisCacheWriter
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final boolean -
Constructor Summary
ConstructorsConstructorDescriptionRedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) Creates a newRedisCacheManagerinitialized with the givenRedisCacheWriterand a defaultRedisCacheConfiguration.RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, boolean allowRuntimeCacheCreation, String... initialCacheNames) Creates a newRedisCacheManagerinitialized with the givenRedisCacheWriterand defaultRedisCacheConfiguration, and whether to allow cache creation at runtime.RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, boolean allowRuntimeCacheCreation, Map<String, RedisCacheConfiguration> initialCacheConfigurations) Creates a newRedisCacheManagerinitialized with the givenRedisCacheWriterand a defaultRedisCacheConfiguration, and whether to allowRedisCachecreation at runtime.RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, String... initialCacheNames) Creates a newRedisCacheManagerinitialized with the givenRedisCacheWriterand a defaultRedisCacheConfiguration, along with an optional, initial set ofcache namesused to createRedis cacheson startup.RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, Map<String, RedisCacheConfiguration> initialCacheConfigurations) RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, Map<String, RedisCacheConfiguration> initialCacheConfigurations, boolean allowRuntimeCacheCreation) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Factory method returning a Builder used to construct and configure aRedisCacheManager.builder(RedisCacheWriter cacheWriter) Factory method returning a Builder used to construct and configure aRedisCacheManagerusing the givenRedisCacheWriter.builder(RedisConnectionFactory connectionFactory) Factory method returning a Builder used to construct and configure aRedisCacheManagerusing the givenRedisConnectionFactory.static RedisCacheManagercreate(RedisConnectionFactory connectionFactory) Factory method used to construct a newRedisCacheManagerusing the givenRedisConnectionFactorywith caching defaults applied.protected RedisCachecreateRedisCache(String name, RedisCacheConfiguration cacheConfiguration) protected RedisCacheConfigurationGets the defaultRedisCacheConfigurationapplied to newRedisCacheinstances on creation when custom, non-specificRedisCacheConfigurationwas not provided.protected Map<String,RedisCacheConfiguration> Gets aMapofcache namestoRedisCacheConfigurationobjects as the initial set ofRedis cachesto create on startup.protected RedisCachegetMissingCache(String name) booleanDetermines whetherRedis cachesare allowed to be created at runtime.protected Collection<RedisCache>Methods inherited from class org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager
decorateCache, isTransactionAware, setTransactionAwareMethods inherited from class org.springframework.cache.support.AbstractCacheManager
afterPropertiesSet, getCache, getCacheNames, initializeCaches, lookupCache
-
Field Details
-
DEFAULT_ALLOW_RUNTIME_CACHE_CREATION
protected static final boolean DEFAULT_ALLOW_RUNTIME_CACHE_CREATION- See Also:
-
-
Constructor Details
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) Creates a newRedisCacheManagerinitialized with the givenRedisCacheWriterand a defaultRedisCacheConfiguration. Allows cache creation at runtime.- Parameters:
cacheWriter-RedisCacheWriterused to performRedisCacheoperations by executing appropriate Redis commands; must not be null.defaultCacheConfiguration-RedisCacheConfigurationapplied to newRedis cachesby default when no cache-specificRedisCacheConfigurationis provided; must not be null.- Throws:
IllegalArgumentException- if either the givenRedisCacheWriterorRedisCacheConfigurationare null.- See Also:
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, String... initialCacheNames) Creates a newRedisCacheManagerinitialized with the givenRedisCacheWriterand a defaultRedisCacheConfiguration, along with an optional, initial set ofcache namesused to createRedis cacheson startup. Allows cache creation at runtime.- Parameters:
cacheWriter-RedisCacheWriterused to performRedisCacheoperations by executing appropriate Redis commands; must not be null.defaultCacheConfiguration-RedisCacheConfigurationapplied to newRedis cachesby default when no cache-specificRedisCacheConfigurationis provided; must not be null.initialCacheNames- optional set ofcache namesused to createRedis cacheson startup. The defaultRedisCacheConfigurationwill be applied to each cache.- Throws:
IllegalArgumentException- if either the givenRedisCacheWriterorRedisCacheConfigurationare null.- See Also:
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, boolean allowRuntimeCacheCreation, String... initialCacheNames) Creates a newRedisCacheManagerinitialized with the givenRedisCacheWriterand defaultRedisCacheConfiguration, and whether to allow cache creation at runtime. Additionally, the optional, initial set ofcache nameswitll be used to createRedis cacheson startup.- Parameters:
cacheWriter-RedisCacheWriterused to performRedisCacheoperations by executing appropriate Redis commands; must not be null.defaultCacheConfiguration-RedisCacheConfigurationapplied to newRedis cachesby default when no cache-specificRedisCacheConfigurationis provided; must not be null.allowRuntimeCacheCreation- boolean to allow creation of undeclared caches at runtime; true by default. Maybe just useRedisCacheConfiguration.defaultCacheConfig().initialCacheNames- optional set ofcache namesused to createRedis cacheson startup. The defaultRedisCacheConfigurationwill be applied to each cache.- Throws:
IllegalArgumentException- if either the givenRedisCacheWriterorRedisCacheConfigurationare null.- Since:
- 2.0.4
- See Also:
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, Map<String, RedisCacheConfiguration> initialCacheConfigurations) Creates newRedisCacheManagerusing givenRedisCacheWriterand defaultRedisCacheConfiguration. Additionally, an initialRedisCachewill be created and configured using the associatedRedisCacheConfigurationfor eachnamedRedisCachein the givenMap. Allows cache creation at runtime.- Parameters:
cacheWriter-RedisCacheWriterused to performRedisCacheoperations by executing appropriate Redis commands; must not be null.defaultCacheConfiguration-RedisCacheConfigurationapplied to newRedis cachesby default when no cache-specificRedisCacheConfigurationis provided; must not be null.initialCacheConfigurations-Mapof declared, knowncache namesalong with associatedRedisCacheConfigurationused to create and configureReds cacheson startup; must not be null.- Throws:
IllegalArgumentException- if either the givenRedisCacheWriterorRedisCacheConfigurationare null.- See Also:
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, boolean allowRuntimeCacheCreation, Map<String, RedisCacheConfiguration> initialCacheConfigurations) Creates a newRedisCacheManagerinitialized with the givenRedisCacheWriterand a defaultRedisCacheConfiguration, and whether to allowRedisCachecreation at runtime. Additionally, an initialRedisCachewill be created and configured using the associatedRedisCacheConfigurationfor eachnamedRedisCachein the givenMap.- Parameters:
cacheWriter-RedisCacheWriterused to performRedisCacheoperations by executing appropriate Redis commands; must not be null.defaultCacheConfiguration-RedisCacheConfigurationapplied to newRedis cachesby default when no cache-specificRedisCacheConfigurationis provided; must not be null.allowRuntimeCacheCreation- boolean to allow creation of undeclared caches at runtime; true by default. Maybe just useRedisCacheConfiguration.defaultCacheConfig().initialCacheConfigurations-Mapof declared, knowncache namesalong with associatedRedisCacheConfigurationused to create and configureRedis cacheson startup; must not be null.- Throws:
IllegalArgumentException- if either the givenRedisCacheWriterorRedisCacheConfigurationare null.- Since:
- 2.0.4
- See Also:
-
RedisCacheManager
@Deprecated public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, Map<String, RedisCacheConfiguration> initialCacheConfigurations, boolean allowRuntimeCacheCreation) Deprecated.
-
-
Method Details
-
builder
Factory method returning a Builder used to construct and configure aRedisCacheManager.- Returns:
- new
RedisCacheManager.RedisCacheManagerBuilder. - Since:
- 2.3
-
builder
Factory method returning a Builder used to construct and configure aRedisCacheManagerusing the givenRedisCacheWriter.- Parameters:
cacheWriter-RedisCacheWriterused to performRedisCacheoperations by executing appropriate Redis commands; must not be null.- Returns:
- new
RedisCacheManager.RedisCacheManagerBuilder. - Throws:
IllegalArgumentException- if the givenRedisCacheWriteris null.- See Also:
-
builder
public static RedisCacheManager.RedisCacheManagerBuilder builder(RedisConnectionFactory connectionFactory) Factory method returning a Builder used to construct and configure aRedisCacheManagerusing the givenRedisConnectionFactory.- Parameters:
connectionFactory-RedisConnectionFactoryused by theRedisCacheManagerto acquire connections to Redis when performingRedisCacheoperations; must not be null.- Returns:
- new
RedisCacheManager.RedisCacheManagerBuilder. - Throws:
IllegalArgumentException- if the givenRedisConnectionFactoryis null.- See Also:
-
create
Factory method used to construct a newRedisCacheManagerusing the givenRedisConnectionFactorywith caching 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-RedisConnectionFactoryused by theRedisCacheManagerto acquire connections to Redis when performingRedisCacheoperations; must not be null.- Returns:
- new
RedisCacheManager. - Throws:
IllegalArgumentException- if the givenRedisConnectionFactoryis null.- See Also:
-
isAllowRuntimeCacheCreation
public boolean isAllowRuntimeCacheCreation()Determines whetherRedis cachesare allowed to be created at runtime.- Returns:
- a boolean value indicating whether
Redis cachesare allowed to be created at runtime.
-
getCacheConfigurations
- Returns:
- unmodifiable
Mapcontainingcache name/configurationpairs.
-
getDefaultCacheConfiguration
Gets the defaultRedisCacheConfigurationapplied to newRedisCacheinstances on creation when custom, non-specificRedisCacheConfigurationwas not provided.- Returns:
- the default
RedisCacheConfiguration.
-
getInitialCacheConfiguration
Gets aMapofcache namestoRedisCacheConfigurationobjects as the initial set ofRedis cachesto create on startup.- Returns:
- a
Mapofcache namestoRedisCacheConfigurationobjects.
-
getMissingCache
- Overrides:
getMissingCachein classorg.springframework.cache.support.AbstractCacheManager
-
createRedisCache
protected RedisCache createRedisCache(String name, @Nullable RedisCacheConfiguration cacheConfiguration) - Parameters:
name-namefor theRedisCache; must not be null.cacheConfiguration-RedisCacheConfigurationused to configure theRedisCache; resolves to thegetDefaultCacheConfiguration()if null.- Returns:
- a new
RedisCacheinstance; never null.
-
loadCaches
- Specified by:
loadCachesin classorg.springframework.cache.support.AbstractCacheManager
-
RedisCacheManager(RedisCacheWriter, RedisCacheConfiguration, boolean, Map)instead.