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:
-
AbstractTransactionSupportingCacheManager
RedisCacheConfiguration
RedisCacheWriter
-
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 a defaultRedisCacheConfiguration
.RedisCacheManager
(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, boolean allowRuntimeCacheCreation, String... initialCacheNames) Creates a newRedisCacheManager
initialized with the givenRedisCacheWriter
and defaultRedisCacheConfiguration
, and 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. -
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
using the givenRedisCacheWriter
.builder
(RedisConnectionFactory connectionFactory) Factory method returning a Builder used to construct and configure aRedisCacheManager
using the givenRedisConnectionFactory
.static RedisCacheManager
create
(RedisConnectionFactory connectionFactory) Factory method used to construct a newRedisCacheManager
using the givenRedisConnectionFactory
with caching defaults applied.protected RedisCache
createRedisCache
(String name, RedisCacheConfiguration cacheConfiguration) 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 a 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
, and whether to allow cache creation at runtime. Additionally, the optional, initial set ofcache names
witll 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 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 initialRedisCache
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 initialRedisCache
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 to allow creation of undeclared caches at runtime; true by default. Maybe just useRedisCacheConfiguration.defaultCacheConfig()
.initialCacheConfigurations
-Map
of declared, knowncache names
along with 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 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 aRedisCacheManager
using 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
using 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
using the givenRedisConnectionFactory
with 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
-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.
-
getMissingCache
- Overrides:
getMissingCache
in classorg.springframework.cache.support.AbstractCacheManager
-
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 classorg.springframework.cache.support.AbstractCacheManager
-
RedisCacheManager(RedisCacheWriter, RedisCacheConfiguration, boolean, Map)
instead.