Class CompositeCacheManager
- All Implemented Interfaces:
InitializingBean
,CacheManager
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.
- Since:
- 3.1
- Author:
- Costin Leau, Juergen Hoeller
- See Also:
-
Constructor Summary
ConstructorDescriptionConstruct 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
Modifier and TypeMethodDescriptionvoid
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.Get the cache associated with the given name.Get a collection of the cache names known by this manager.void
setCacheManagers
(Collection<CacheManager> cacheManagers) Specify the CacheManagers to delegate to.void
setFallbackToNoOpCache
(boolean fallbackToNoOpCache) Indicate whether aNoOpCacheManager
should be added at the end of the delegate list.
-
Constructor Details
-
CompositeCacheManager
public CompositeCacheManager()Construct an empty CompositeCacheManager, with delegate CacheManagers to be added via the"cacheManagers"
property. -
CompositeCacheManager
Construct a CompositeCacheManager from the given delegate CacheManagers.- Parameters:
cacheManagers
- the CacheManagers to delegate to
-
-
Method Details
-
setCacheManagers
Specify the CacheManagers to delegate to. -
setFallbackToNoOpCache
public void setFallbackToNoOpCache(boolean fallbackToNoOpCache) Indicate whether aNoOpCacheManager
should be added at the end of the delegate list. In this case, anygetCache
requests not handled by the configured CacheManagers will be automatically handled by theNoOpCacheManager
(and hence never returnnull
). -
afterPropertiesSet
public void afterPropertiesSet()Description copied from interface:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,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.
- Specified by:
afterPropertiesSet
in interfaceInitializingBean
-
getCache
Description copied from interface:CacheManager
Get 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:
getCache
in interfaceCacheManager
- Parameters:
name
- the cache identifier (must not benull
)- Returns:
- the associated cache, or
null
if such a cache does not exist or could be not created
-
getCacheNames
Description copied from interface:CacheManager
Get a collection of the cache names known by this manager.- Specified by:
getCacheNames
in interfaceCacheManager
- Returns:
- the names of all caches known by the cache manager
-