public class CompositeCacheManager extends java.lang.Object implements CacheManager, InitializingBean
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.
setFallbackToNoOpCache(boolean)
,
ConcurrentMapCacheManager.setCacheNames(java.util.Collection<java.lang.String>)
Constructor and 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.
|
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied
(and satisfied BeanFactoryAware and ApplicationContextAware).
|
Cache |
getCache(java.lang.String name)
Return the cache associated with the given name.
|
java.util.Collection<java.lang.String> |
getCacheNames()
Return a collection of the cache names known by this manager.
|
void |
setCacheManagers(java.util.Collection<CacheManager> cacheManagers)
Specify the CacheManagers to delegate to.
|
void |
setFallbackToNoOpCache(boolean fallbackToNoOpCache)
Indicate whether a
NoOpCacheManager should be added at the end of the delegate list. |
public CompositeCacheManager()
"cacheManagers"
property.public CompositeCacheManager(CacheManager... cacheManagers)
cacheManagers
- the CacheManagers to delegate topublic void setCacheManagers(java.util.Collection<CacheManager> cacheManagers)
public void setFallbackToNoOpCache(boolean fallbackToNoOpCache)
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
).public void afterPropertiesSet()
InitializingBean
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet
in interface InitializingBean
public Cache getCache(java.lang.String name)
CacheManager
getCache
in interface CacheManager
name
- the cache identifier (must not be null
)null
if none foundpublic java.util.Collection<java.lang.String> getCacheNames()
CacheManager
getCacheNames
in interface CacheManager