Class RedisCacheManager
- All Implemented Interfaces:
InitializingBean
,CacheManager
CacheManager
implementation for Redis backed by RedisCache
.
This CacheManager
creates caches
on first write, by default. Empty caches
are not visible in Redis due to how Redis represents empty data structures.
Caches
requiring a different cache configuration
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:
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final boolean
-
Constructor Summary
ConstructorDescriptionRedisCacheManager
(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) Creates a newRedisCacheManager
initialized with the givenRedisCacheWriter
and defaultRedisCacheConfiguration
.RedisCacheManager
(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, boolean allowRuntimeCacheCreation, String... initialCacheNames) Creates a newRedisCacheManager
initialized with the givenRedisCacheWriter
and defaultRedisCacheConfiguration
along with whether to allow cache creation at runtime.RedisCacheManager
(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, boolean allowRuntimeCacheCreation, Map<String, RedisCacheConfiguration> initialCacheConfigurations) Creates a newRedisCacheManager
initialized with the givenRedisCacheWriter
and a defaultRedisCacheConfiguration
, and whether to allowRedisCache
creation at runtime.RedisCacheManager
(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, String... initialCacheNames) Creates a newRedisCacheManager
initialized with the givenRedisCacheWriter
and a defaultRedisCacheConfiguration
along with an optional, initial set ofcache names
used to createRedis caches
on startup.RedisCacheManager
(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, Map<String, RedisCacheConfiguration> initialCacheConfigurations) RedisCacheManager
(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, Map<String, RedisCacheConfiguration> initialCacheConfigurations, boolean allowRuntimeCacheCreation) Deprecated.since 3.2. -
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 aRedisCacheManager
initialized with the givenRedisCacheWriter
.builder
(RedisConnectionFactory connectionFactory) Factory method returning a Builder used to construct and configure aRedisCacheManager
initialized with the givenRedisConnectionFactory
.static RedisCacheManager
create
(RedisConnectionFactory connectionFactory) Factory method used to construct a newRedisCacheManager
initialized with the givenRedisConnectionFactory
and usingdefaults
for caching.protected RedisCache
createRedisCache
(String name, RedisCacheConfiguration cacheConfiguration) protected RedisCacheWriter
Returns a reference to the configuredRedisCacheWriter
used to performRedisCache
operations, such as reading from and writing to the cache.protected RedisCacheConfiguration
Gets the defaultRedisCacheConfiguration
applied to newRedisCache
instances on creation when custom, non-specificRedisCacheConfiguration
was not provided.protected Map<String,
RedisCacheConfiguration> Gets aMap
ofcache names
toRedisCacheConfiguration
objects as the initial set ofRedis caches
to create on startup.protected RedisCache
getMissingCache
(String name) boolean
Determines whetherRedis caches
are allowed to be created at runtime.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
-
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 newRedisCacheManager
initialized with the givenRedisCacheWriter
and defaultRedisCacheConfiguration
.Allows
cache
creation at runtime.- Parameters:
cacheWriter
-RedisCacheWriter
used to performRedisCache
operations by executing appropriate Redis commands; must not be null.defaultCacheConfiguration
-RedisCacheConfiguration
applied to newRedis caches
by default when no cache-specificRedisCacheConfiguration
is provided; must not be null.- Throws:
IllegalArgumentException
- if either the givenRedisCacheWriter
orRedisCacheConfiguration
are null.- See Also:
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, String... initialCacheNames) Creates a newRedisCacheManager
initialized with the givenRedisCacheWriter
and a defaultRedisCacheConfiguration
along with an optional, initial set ofcache names
used to createRedis caches
on startup.Allows
cache
creation at runtime.- Parameters:
cacheWriter
-RedisCacheWriter
used to performRedisCache
operations by executing appropriate Redis commands; must not be null.defaultCacheConfiguration
-RedisCacheConfiguration
applied to newRedis caches
by default when no cache-specificRedisCacheConfiguration
is provided; must not be null.initialCacheNames
- optional set ofcache names
used to createRedis caches
on startup. The defaultRedisCacheConfiguration
will be applied to each cache.- Throws:
IllegalArgumentException
- if either the givenRedisCacheWriter
orRedisCacheConfiguration
are null.- See Also:
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, boolean allowRuntimeCacheCreation, String... initialCacheNames) Creates a newRedisCacheManager
initialized with the givenRedisCacheWriter
and defaultRedisCacheConfiguration
along with whether to allow cache creation at runtime.Additionally, the optional, initial set of
cache names
will be used to createRedis caches
on startup.- Parameters:
cacheWriter
-RedisCacheWriter
used to performRedisCache
operations by executing appropriate Redis commands; must not be null.defaultCacheConfiguration
-RedisCacheConfiguration
applied to newRedis caches
by default when no cache-specificRedisCacheConfiguration
is provided; must not be null.allowRuntimeCacheCreation
- boolean specifying whether to allow creation of undeclared caches at runtime; true by default. Maybe just useRedisCacheConfiguration.defaultCacheConfig()
.initialCacheNames
- optional set ofcache names
used to createRedis caches
on startup. The defaultRedisCacheConfiguration
will be applied to each cache.- Throws:
IllegalArgumentException
- if either the givenRedisCacheWriter
orRedisCacheConfiguration
are null.- Since:
- 2.0.4
- See Also:
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, Map<String, RedisCacheConfiguration> initialCacheConfigurations) Creates newRedisCacheManager
using givenRedisCacheWriter
and defaultRedisCacheConfiguration
.Additionally, an initial
RedisCache
will be created and configured using the associatedRedisCacheConfiguration
for eachnamed
RedisCache
in the givenMap
.Allows
cache
creation at runtime.- Parameters:
cacheWriter
-RedisCacheWriter
used to performRedisCache
operations by executing appropriate Redis commands; must not be null.defaultCacheConfiguration
-RedisCacheConfiguration
applied to newRedis caches
by default when no cache-specificRedisCacheConfiguration
is provided; must not be null.initialCacheConfigurations
-Map
of declared, knowncache names
along with associatedRedisCacheConfiguration
used to create and configureReds caches
on startup; must not be null.- Throws:
IllegalArgumentException
- if either the givenRedisCacheWriter
orRedisCacheConfiguration
are null.- See Also:
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, boolean allowRuntimeCacheCreation, Map<String, RedisCacheConfiguration> initialCacheConfigurations) Creates a newRedisCacheManager
initialized with the givenRedisCacheWriter
and a defaultRedisCacheConfiguration
, and whether to allowRedisCache
creation at runtime.Additionally, an initial
RedisCache
will be created and configured using the associatedRedisCacheConfiguration
for eachnamed
RedisCache
in the givenMap
.- Parameters:
cacheWriter
-RedisCacheWriter
used to performRedisCache
operations by executing appropriate Redis commands; must not be null.defaultCacheConfiguration
-RedisCacheConfiguration
applied to newRedis caches
by default when no cache-specificRedisCacheConfiguration
is provided; must not be null.allowRuntimeCacheCreation
- boolean specifying whether to allow creation of undeclared caches at runtime; true by default. Maybe just useRedisCacheConfiguration.defaultCacheConfig()
.initialCacheConfigurations
-Map
of declared, knowncache names
along with the associatedRedisCacheConfiguration
used to create and configureRedis caches
on startup; must not be null.- Throws:
IllegalArgumentException
- if either the givenRedisCacheWriter
orRedisCacheConfiguration
are null.- Since:
- 2.0.4
- See Also:
-
RedisCacheManager
@Deprecated(since="3.2") public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, Map<String, RedisCacheConfiguration> initialCacheConfigurations, boolean allowRuntimeCacheCreation) Deprecated.since 3.2. UseRedisCacheManager(RedisCacheWriter, RedisCacheConfiguration, boolean, Map)
instead.
-
-
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 aRedisCacheManager
initialized with the givenRedisCacheWriter
.- Parameters:
cacheWriter
-RedisCacheWriter
used to performRedisCache
operations by executing appropriate Redis commands; must not be null.- Returns:
- new
RedisCacheManager.RedisCacheManagerBuilder
. - Throws:
IllegalArgumentException
- if the givenRedisCacheWriter
is null.- See Also:
-
builder
public static RedisCacheManager.RedisCacheManagerBuilder builder(RedisConnectionFactory connectionFactory) Factory method returning a Builder used to construct and configure aRedisCacheManager
initialized with the givenRedisConnectionFactory
.- Parameters:
connectionFactory
-RedisConnectionFactory
used by theRedisCacheManager
to acquire connections to Redis when performingRedisCache
operations; must not be null.- Returns:
- new
RedisCacheManager.RedisCacheManagerBuilder
. - Throws:
IllegalArgumentException
- if the givenRedisConnectionFactory
is null.- See Also:
-
create
Factory method used to construct a newRedisCacheManager
initialized with the givenRedisConnectionFactory
and usingdefaults
for caching.- locking
- disabled
- batch strategy
BatchStrategies.keys()
- cache configuration
RedisCacheConfiguration.defaultCacheConfig()
- initial caches
- none
- transaction aware
- no
- in-flight cache creation
- enabled
- Parameters:
connectionFactory
-RedisConnectionFactory
used by theRedisCacheManager
to acquire connections to Redis when performingRedisCache
operations; must not be null.- Returns:
- new
RedisCacheManager
. - Throws:
IllegalArgumentException
- if the givenRedisConnectionFactory
is null.- See Also:
-
isAllowRuntimeCacheCreation
public boolean isAllowRuntimeCacheCreation()Determines whetherRedis caches
are allowed to be created at runtime.- Returns:
- a boolean value indicating whether
Redis caches
are allowed to be created at runtime.
-
getCacheConfigurations
- Returns:
- unmodifiable
Map
containingcache name
/configuration
pairs.
-
getDefaultCacheConfiguration
Gets the defaultRedisCacheConfiguration
applied to newRedisCache
instances on creation when custom, non-specificRedisCacheConfiguration
was not provided.- Returns:
- the default
RedisCacheConfiguration
.
-
getInitialCacheConfiguration
Gets aMap
ofcache names
toRedisCacheConfiguration
objects as the initial set ofRedis caches
to create on startup.- Returns:
- a
Map
ofcache names
toRedisCacheConfiguration
objects.
-
getCacheWriter
Returns a reference to the configuredRedisCacheWriter
used to performRedisCache
operations, such as reading from and writing to the cache.- Returns:
- a reference to the configured
RedisCacheWriter
. - See Also:
-
getMissingCache
- Overrides:
getMissingCache
in classAbstractCacheManager
-
createRedisCache
protected RedisCache createRedisCache(String name, @Nullable RedisCacheConfiguration cacheConfiguration) - Parameters:
name
-name
for theRedisCache
; must not be null.cacheConfiguration
-RedisCacheConfiguration
used to configure theRedisCache
; resolves to thegetDefaultCacheConfiguration()
if null.- Returns:
- a new
RedisCache
instance; never null.
-
loadCaches
- Specified by:
loadCaches
in classAbstractCacheManager
-