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 ofRedisCacheManagerwith configuration options applied.Returns the defaultRedisCacheConfiguration.cacheDefaults(RedisCacheConfiguration defaultCacheConfiguration) Define a defaultRedisCacheConfigurationapplied to dynamically createdRedisCaches.cacheWriter(RedisCacheWriter cacheWriter) Configure aRedisCacheWriter.DisableRedisCachecreation at runtime for non-configured, undeclared caches.EnablesRedisCachecreation at runtime for unconfigured, undeclared caches.Enables cache statistics.fromCacheWriter(RedisCacheWriter cacheWriter) Factory method returning a new Builder used to create and configure aRedisCacheManagerusing the givenRedisCacheWriter.fromConnectionFactory(RedisConnectionFactory connectionFactory) Factory method returning a new Builder used to create and configure aRedisCacheManagerusing the givenRedisConnectionFactory.getCacheConfigurationFor(String cacheName) Get theRedisCacheConfigurationfor a given cache by its name.Get theSetof cache names for which the builder holdsconfiguration.initialCacheNames(Set<String> cacheNames) Append aSetof cache names to be pre initialized with currentRedisCacheConfiguration.EnableRedisCaches to synchronize cache put/evict operations with ongoing Spring-managed transactions.withCacheConfiguration(String cacheName, RedisCacheConfiguration cacheConfiguration) Registers the givencache nameandRedisCacheConfigurationused to create and configure aRedisCacheon startup.withInitialCacheConfigurations(Map<String, RedisCacheConfiguration> cacheConfigurations) Append aMapof cache name/RedisCacheConfigurationpairs 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 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:
-
fromConnectionFactory
public static RedisCacheManager.RedisCacheManagerBuilder fromConnectionFactory(RedisConnectionFactory connectionFactory) Factory method returning a new Builder used to create 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:
-
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
DisableRedisCachecreation at runtime for non-configured, undeclared caches.RedisCacheManager.getMissingCache(String)returns null for any non-configured, undeclaredCacheinstead of a newRedisCacheinstance. This allows theCompositeCacheManagerto participate.- Returns:
- this
RedisCacheManager.RedisCacheManagerBuilder. - Since:
- 2.0.4
- See Also:
-
enableCreateOnMissingCache
EnablesRedisCachecreation 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 defaultRedisCacheConfigurationapplied to dynamically createdRedisCaches.- 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 aSetof cache names to be pre initialized with currentRedisCacheConfiguration. NOTE: This calls depends oncacheDefaults(RedisCacheConfiguration)using whatever defaultRedisCacheConfigurationis present at the time of invoking this method.- Parameters:
cacheNames- must not be null.- Returns:
- this
RedisCacheManager.RedisCacheManagerBuilder.
-
transactionAware
EnableRedisCaches 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 nameandRedisCacheConfigurationused to create and configure aRedisCacheon startup.- Parameters:
cacheName-nameof the cache to register for creation on startup.cacheConfiguration-RedisCacheConfigurationused to configure the new cache on startup.- Returns:
- this
RedisCacheManager.RedisCacheManagerBuilder. - Since:
- 2.2
-
withInitialCacheConfigurations
public RedisCacheManager.RedisCacheManagerBuilder withInitialCacheConfigurations(Map<String, RedisCacheConfiguration> cacheConfigurations) Append aMapof cache name/RedisCacheConfigurationpairs to be pre initialized.- Parameters:
cacheConfigurations- must not be null.- Returns:
- this
RedisCacheManager.RedisCacheManagerBuilder.
-
getCacheConfigurationFor
Get theRedisCacheConfigurationfor a given cache by its name.- Parameters:
cacheName- must not be null.- Returns:
Optional.empty()if noRedisCacheConfigurationset for the given cache name.- Since:
- 2.2
-
getConfiguredCaches
Get theSetof cache names for which the builder holdsconfiguration.- Returns:
- an unmodifiable
Setholding the name of caches for which aconfigurationhas been set. - Since:
- 2.2
-
build
Create new instance ofRedisCacheManagerwith configuration options applied.- Returns:
- new instance of
RedisCacheManager.
-