Top Description Fields Constructors Methods
org.springframework.cache.support

public Class CompositeCacheManager

extends Object
implements CacheManager, InitializingBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.InitializingBean, org.springframework.cache.CacheManager
Imports
java.util.ArrayList, .Arrays, .Collection, .Collections, .LinkedHashSet, .List, .Set, org.springframework.beans.factory.InitializingBean, org.springframework.cache.Cache, .CacheManager, org.springframework.lang.Nullable

Composite CacheManager implementation that iterates over a given collection of delegate CacheManager instances.

Allows NoOpCacheManager to be automatically added to the end of the list for handling cache declarations without a backing store. Otherwise, any custom CacheManager may 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 null from getCache(String) if they are unaware of the specified cache name, allowing for iteration to the next delegate in line. However, most CacheManager implementations 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.

Authors
Costin Leau, Juergen Hoeller
Since
3.1
See Also
setFallbackToNoOpCache, org.springframework.cache.concurrent.ConcurrentMapCacheManager#setCacheNames

Field Summary

Modifier and TypeField and Description
private final List<CacheManager>
private boolean

Constructor Summary

AccessConstructor and Description
public
CompositeCacheManager()

Construct an empty CompositeCacheManager, with delegate CacheManagers to be added via the "cacheManagers" property.

public
CompositeCacheManager(CacheManager...
the CacheManagers to delegate to
cacheManagers
)

Construct a CompositeCacheManager from the given delegate CacheManagers.

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

public Cache
getCache(String
the cache identifier (must not be null)
name
)

Implements org.springframework.cache.CacheManager.getCache.

Get the cache associated with the given name.
public Collection<String>
getCacheNames()

Implements org.springframework.cache.CacheManager.getCacheNames.

Get a collection of the cache names known by this manager.
public void
setCacheManagers(Collection<CacheManager> cacheManagers)

Specify the CacheManagers to delegate to.

public void
setFallbackToNoOpCache(boolean fallbackToNoOpCache)

Indicate whether a NoOpCacheManager should be added at the end of the delegate list.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheManagersback to summary
private final List<CacheManager> cacheManagers
fallbackToNoOpCacheback to summary
private boolean fallbackToNoOpCache

Constructor Detail

CompositeCacheManagerback to summary
public CompositeCacheManager()

Construct an empty CompositeCacheManager, with delegate CacheManagers to be added via the "cacheManagers" property.

CompositeCacheManagerback to summary
public CompositeCacheManager(CacheManager... cacheManagers)

Construct a CompositeCacheManager from the given delegate CacheManagers.

Parameters
cacheManagers:CacheManager[]

the CacheManagers to delegate to

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Doc from org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

Annotations
@Override
getCacheback to summary
public Cache getCache(String name)

Implements org.springframework.cache.CacheManager.getCache.

Doc from org.springframework.cache.CacheManager.getCache.

Get the cache associated with the given name.

Note that the cache may be lazily created at runtime if the native provider supports it.

Parameters
name:String

the cache identifier (must not be null)

Returns:Cache

the associated cache, or null if such a cache does not exist or could be not created

Annotations
@Override
@Nullable
getCacheNamesback to summary
public Collection<String> getCacheNames()

Implements org.springframework.cache.CacheManager.getCacheNames.

Doc from org.springframework.cache.CacheManager.getCacheNames.

Get a collection of the cache names known by this manager.

Returns:Collection<String>

the names of all caches known by the cache manager

Annotations
@Override
setCacheManagersback to summary
public void setCacheManagers(Collection<CacheManager> cacheManagers)

Specify the CacheManagers to delegate to.

setFallbackToNoOpCacheback to summary
public void setFallbackToNoOpCache(boolean fallbackToNoOpCache)

Indicate whether a NoOpCacheManager should be added at the end of the delegate list. In this case, any getCache requests not handled by the configured CacheManagers will be automatically handled by the NoOpCacheManager (and hence never return null).