Class CompositeCacheManager
- java.lang.Object
- org.springframework.cache.support.CompositeCacheManager
- All Implemented Interfaces:
InitializingBean,CacheManager
public class CompositeCacheManager extends Object implements CacheManager, InitializingBean
CompositeCacheManagerimplementation that iterates over a given collection of delegateCacheManagerinstances.Allows
NoOpCacheManagerto be automatically added to the end of the list for handling cache declarations without a backing store. Otherwise, any customCacheManagermay play that role of the last delegate as well, lazily creating cache regions for any requested name.Note: Regular CacheManagers that this composite manager delegates to need to return
nullfromgetCache(String)if they are unaware of the specified cache name, allowing for iteration to the next delegate in line. However, mostCacheManagerimplementations fall back to lazy creation of named caches once requested; check out the specific configuration details for a 'static' mode with fixed cache names, if available.- Since:
- 3.1
- Author:
- Costin Leau, Juergen Hoeller
- See Also:
setFallbackToNoOpCache(boolean),ConcurrentMapCacheManager.setCacheNames(java.util.Collection<java.lang.String>)
Constructor Summary
Constructors Constructor Description CompositeCacheManager()Construct an empty CompositeCacheManager, with delegate CacheManagers to be added via the"cacheManagers"property.CompositeCacheManager(CacheManager... cacheManagers)Construct a CompositeCacheManager from the given delegate CacheManagers.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()Invoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.CachegetCache(String name)Get the cache associated with the given name.Collection<String>getCacheNames()Get a collection of the cache names known by this manager.voidsetCacheManagers(Collection<CacheManager> cacheManagers)Specify the CacheManagers to delegate to.voidsetFallbackToNoOpCache(boolean fallbackToNoOpCache)Indicate whether aNoOpCacheManagershould be added at the end of the delegate list.
Constructor Detail
CompositeCacheManager
public CompositeCacheManager()
Construct an empty CompositeCacheManager, with delegate CacheManagers to be added via the"cacheManagers"property.
CompositeCacheManager
public CompositeCacheManager(CacheManager... cacheManagers)
Construct a CompositeCacheManager from the given delegate CacheManagers.- Parameters:
cacheManagers- the CacheManagers to delegate to
Method Detail
setCacheManagers
public void setCacheManagers(Collection<CacheManager> cacheManagers)
Specify the CacheManagers to delegate to.
setFallbackToNoOpCache
public void setFallbackToNoOpCache(boolean fallbackToNoOpCache)
Indicate whether aNoOpCacheManagershould be added at the end of the delegate list. In this case, anygetCacherequests not handled by the configured CacheManagers will be automatically handled by theNoOpCacheManager(and hence never returnnull).
afterPropertiesSet
public void afterPropertiesSet()
Description copied from interface:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- Specified by:
afterPropertiesSetin interfaceInitializingBean
getCache
@Nullable public Cache getCache(String name)
Description copied from interface:CacheManagerGet the cache associated with the given name.Note that the cache may be lazily created at runtime if the native provider supports it.
- Specified by:
getCachein interfaceCacheManager- Parameters:
name- the cache identifier (must not benull)- Returns:
- the associated cache, or
nullif such a cache does not exist or could be not created
getCacheNames
public Collection<String> getCacheNames()
Description copied from interface:CacheManagerGet a collection of the cache names known by this manager.- Specified by:
getCacheNamesin interfaceCacheManager- Returns:
- the names of all caches known by the cache manager