Class RedisCacheManager.RedisCacheManagerBuilder
java.lang.Object
org.springframework.data.redis.cache.RedisCacheManager.RedisCacheManagerBuilder
- Enclosing class:
- RedisCacheManager
Builder for creating a
RedisCacheManager
.- Since:
- 2.0
- Author:
- Christoph Strobl, Mark Paluch, Kezhu Wang, John Blum
-
Method Summary
Modifier and TypeMethodDescriptionallowCreateOnMissingCache
(boolean allowRuntimeCacheCreation) Configure whether to allow cache creation at runtime.build()
Create new instance ofRedisCacheManager
with configuration options applied.Returns the defaultRedisCacheConfiguration
.cacheDefaults
(RedisCacheConfiguration defaultCacheConfiguration) Define a defaultRedisCacheConfiguration
applied to dynamically createdRedisCache
s.cacheWriter
(RedisCacheWriter cacheWriter) Configure aRedisCacheWriter
.DisableRedisCache
creation at runtime for non-configured, undeclared caches.EnablesRedisCache
creation at runtime for unconfigured, undeclared caches.Enables cache statistics.fromCacheWriter
(RedisCacheWriter cacheWriter) Factory method returning a new Builder used to create and configure aRedisCacheManager
using the givenRedisCacheWriter
.fromConnectionFactory
(RedisConnectionFactory connectionFactory) Factory method returning a new Builder used to create and configure aRedisCacheManager
using the givenRedisConnectionFactory
.getCacheConfigurationFor
(String cacheName) Get theRedisCacheConfiguration
for a given cache by its name.Get theSet
of cache names for which the builder holdsconfiguration
.initialCacheNames
(Set<String> cacheNames) Append aSet
of cache names to be pre initialized with currentRedisCacheConfiguration
.EnableRedisCache
s to synchronize cache put/evict operations with ongoing Spring-managed transactions.withCacheConfiguration
(String cacheName, RedisCacheConfiguration cacheConfiguration) Registers the givencache name
andRedisCacheConfiguration
used to create and configure aRedisCache
on startup.withInitialCacheConfigurations
(Map<String, RedisCacheConfiguration> cacheConfigurations) Append aMap
of cache name/RedisCacheConfiguration
pairs to be pre initialized.
-
Method Details
-
fromCacheWriter
public static RedisCacheManager.RedisCacheManagerBuilder fromCacheWriter(RedisCacheWriter cacheWriter) Factory method returning a new Builder used to create 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:
-
fromConnectionFactory
public static RedisCacheManager.RedisCacheManagerBuilder fromConnectionFactory(RedisConnectionFactory connectionFactory) Factory method returning a new Builder used to create 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:
-
allowCreateOnMissingCache
public RedisCacheManager.RedisCacheManagerBuilder allowCreateOnMissingCache(boolean allowRuntimeCacheCreation) Configure whether to allow cache creation at runtime.- Parameters:
allowRuntimeCacheCreation
- boolean to allow creation of undeclared caches at runtime; true by default.- Returns:
- this
RedisCacheManager.RedisCacheManagerBuilder
.
-
disableCreateOnMissingCache
DisableRedisCache
creation at runtime for non-configured, undeclared caches.RedisCacheManager.getMissingCache(String)
returns null for any non-configured, undeclaredCache
instead of a newRedisCache
instance. This allows theCompositeCacheManager
to participate.- Returns:
- this
RedisCacheManager.RedisCacheManagerBuilder
. - Since:
- 2.0.4
- See Also:
-
enableCreateOnMissingCache
EnablesRedisCache
creation at runtime for unconfigured, undeclared caches.- Returns:
- this
RedisCacheManager.RedisCacheManagerBuilder
. - Since:
- 2.0.4
- See Also:
-
cacheDefaults
Returns the defaultRedisCacheConfiguration
.- Returns:
- the default
RedisCacheConfiguration
.
-
cacheDefaults
public RedisCacheManager.RedisCacheManagerBuilder cacheDefaults(RedisCacheConfiguration defaultCacheConfiguration) Define a defaultRedisCacheConfiguration
applied to dynamically createdRedisCache
s.- Parameters:
defaultCacheConfiguration
- must not be null.- Returns:
- this
RedisCacheManager.RedisCacheManagerBuilder
.
-
cacheWriter
Configure aRedisCacheWriter
.- Parameters:
cacheWriter
- must not be null.- Returns:
- this
RedisCacheManager.RedisCacheManagerBuilder
. - Since:
- 2.3
-
enableStatistics
Enables cache statistics.- Returns:
- this
RedisCacheManager.RedisCacheManagerBuilder
.
-
initialCacheNames
Append aSet
of cache names to be pre initialized with currentRedisCacheConfiguration
. NOTE: This calls depends oncacheDefaults(RedisCacheConfiguration)
using whatever defaultRedisCacheConfiguration
is present at the time of invoking this method.- Parameters:
cacheNames
- must not be null.- Returns:
- this
RedisCacheManager.RedisCacheManagerBuilder
.
-
transactionAware
EnableRedisCache
s to synchronize cache put/evict operations with ongoing Spring-managed transactions.- Returns:
- this
RedisCacheManager.RedisCacheManagerBuilder
.
-
withCacheConfiguration
public RedisCacheManager.RedisCacheManagerBuilder withCacheConfiguration(String cacheName, RedisCacheConfiguration cacheConfiguration) Registers the givencache name
andRedisCacheConfiguration
used to create and configure aRedisCache
on startup.- Parameters:
cacheName
-name
of the cache to register for creation on startup.cacheConfiguration
-RedisCacheConfiguration
used to configure the new cache on startup.- Returns:
- this
RedisCacheManager.RedisCacheManagerBuilder
. - Since:
- 2.2
-
withInitialCacheConfigurations
public RedisCacheManager.RedisCacheManagerBuilder withInitialCacheConfigurations(Map<String, RedisCacheConfiguration> cacheConfigurations) Append aMap
of cache name/RedisCacheConfiguration
pairs to be pre initialized.- Parameters:
cacheConfigurations
- must not be null.- Returns:
- this
RedisCacheManager.RedisCacheManagerBuilder
.
-
getCacheConfigurationFor
Get theRedisCacheConfiguration
for a given cache by its name.- Parameters:
cacheName
- must not be null.- Returns:
Optional.empty()
if noRedisCacheConfiguration
set for the given cache name.- Since:
- 2.2
-
getConfiguredCaches
Get theSet
of cache names for which the builder holdsconfiguration
.- Returns:
- an unmodifiable
Set
holding the name of caches for which aconfiguration
has been set. - Since:
- 2.2
-
build
Create new instance ofRedisCacheManager
with configuration options applied.- Returns:
- new instance of
RedisCacheManager
.
-