Class RedisCacheManager
java.lang.Object
org.springframework.cache.support.AbstractCacheManager
org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager
org.springframework.data.redis.cache.RedisCacheManager
- All Implemented Interfaces:
InitializingBean,CacheManager
CacheManager backed by a Redis cache.
This cache manager creates caches by default upon first write. Empty caches are not visible on Redis due to how Redis represents empty data structures.
Caches requiring a different RedisCacheConfiguration than the default configuration can be specified via
RedisCacheManager.RedisCacheManagerBuilder.withInitialCacheConfigurations(Map).
- Since:
- 2.0
- Author:
- Christoph Strobl, Mark Paluch
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionRedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, boolean allowInFlightCacheCreation, String... initialCacheNames) RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, String... initialCacheNames) RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, Map<String, RedisCacheConfiguration> initialCacheConfigurations) RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, Map<String, RedisCacheConfiguration> initialCacheConfigurations, boolean allowInFlightCacheCreation) -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Entry point for builder styleRedisCacheManagerconfiguration.builder(RedisCacheWriter cacheWriter) Entry point for builder styleRedisCacheManagerconfiguration.builder(RedisConnectionFactory connectionFactory) Entry point for builder styleRedisCacheManagerconfiguration.static RedisCacheManagercreate(RedisConnectionFactory connectionFactory) Create a newRedisCacheManagerwith defaults applied.protected RedisCachecreateRedisCache(String name, RedisCacheConfiguration cacheConfig) Configuration hook for creatingRedisCachewith given name andcacheConfig.protected RedisCachegetMissingCache(String name) 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
-
Constructor Details
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) - Parameters:
cacheWriter- must not be null.defaultCacheConfiguration- must not be null. Maybe just useRedisCacheConfiguration.defaultCacheConfig().
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, String... initialCacheNames) - Parameters:
cacheWriter- must not be null.defaultCacheConfiguration- must not be null. Maybe just useRedisCacheConfiguration.defaultCacheConfig().initialCacheNames- optional set of known cache names that will be created with given defaultCacheConfiguration.
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, boolean allowInFlightCacheCreation, String... initialCacheNames) - Parameters:
cacheWriter- must not be null.defaultCacheConfiguration- must not be null. Maybe just useRedisCacheConfiguration.defaultCacheConfig().allowInFlightCacheCreation- if set to true no new caches can be acquire at runtime but limited to the given list of initial cache names.initialCacheNames- optional set of known cache names that will be created with given defaultCacheConfiguration.- Since:
- 2.0.4
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, Map<String, RedisCacheConfiguration> initialCacheConfigurations) - Parameters:
cacheWriter- must not be null.defaultCacheConfiguration- must not be null. Maybe just useRedisCacheConfiguration.defaultCacheConfig().initialCacheConfigurations- Map of known cache names along with the configuration to use for those caches. Must not be null.
-
RedisCacheManager
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration, Map<String, RedisCacheConfiguration> initialCacheConfigurations, boolean allowInFlightCacheCreation) - Parameters:
cacheWriter- must not be null.defaultCacheConfiguration- must not be null. Maybe just useRedisCacheConfiguration.defaultCacheConfig().initialCacheConfigurations- Map of known cache names along with the configuration to use for those caches. Must not be null.allowInFlightCacheCreation- if set to false this cache manager is limited to the initial cache configurations and will not create new caches at runtime.- Since:
- 2.0.4
-
-
Method Details
-
create
Create a newRedisCacheManagerwith 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- must not be null.- Returns:
- new instance of
RedisCacheManager.
-
builder
Entry point for builder styleRedisCacheManagerconfiguration.- Returns:
- new
RedisCacheManager.RedisCacheManagerBuilder. - Since:
- 2.3
-
builder
public static RedisCacheManager.RedisCacheManagerBuilder builder(RedisConnectionFactory connectionFactory) Entry point for builder styleRedisCacheManagerconfiguration.- Parameters:
connectionFactory- must not be null.- Returns:
- new
RedisCacheManager.RedisCacheManagerBuilder.
-
builder
Entry point for builder styleRedisCacheManagerconfiguration.- Parameters:
cacheWriter- must not be null.- Returns:
- new
RedisCacheManager.RedisCacheManagerBuilder.
-
loadCaches
- Specified by:
loadCachesin classAbstractCacheManager
-
getMissingCache
- Overrides:
getMissingCachein classAbstractCacheManager
-
getCacheConfigurations
- Returns:
- unmodifiable
Mapcontaining cache name / configuration pairs. Never null.
-
createRedisCache
Configuration hook for creatingRedisCachewith given name andcacheConfig.- Parameters:
name- must not be null.cacheConfig- can be null.- Returns:
- never null.
-