public abstract class AbstractCacheManager extends java.lang.Object implements CacheManager, InitializingBean
CacheManager
methods.
Useful for 'static' environments where the backing caches do not change.Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.ConcurrentMap<java.lang.String,Cache> |
cacheMap |
private java.util.Set<java.lang.String> |
cacheNames |
Constructor and Description |
---|
AbstractCacheManager() |
Modifier and Type | Method and Description |
---|---|
protected void |
addCache(Cache cache)
Deprecated.
as of Spring 4.3, in favor of
getMissingCache(String) |
void |
afterPropertiesSet()
Invoked by the containing
BeanFactory after it has set all bean properties
and satisfied BeanFactoryAware , ApplicationContextAware etc. |
protected Cache |
decorateCache(Cache cache)
Decorate the given Cache object if necessary.
|
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.
|
protected Cache |
getMissingCache(java.lang.String name)
Return a missing cache with the specified
name or null if
such cache does not exist or could not be created on the fly. |
void |
initializeCaches()
Initialize the static configuration of caches.
|
protected abstract java.util.Collection<? extends Cache> |
loadCaches()
Load the initial caches for this cache manager.
|
protected Cache |
lookupCache(java.lang.String name)
Check for a registered cache of the given name.
|
private void |
updateCacheNames(java.lang.String name)
Update the exposed
cacheNames set with the given name. |
private final java.util.concurrent.ConcurrentMap<java.lang.String,Cache> cacheMap
private volatile java.util.Set<java.lang.String> cacheNames
public void afterPropertiesSet()
InitializingBean
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.
afterPropertiesSet
in interface InitializingBean
public void initializeCaches()
Triggered on startup through afterPropertiesSet()
;
can also be called to re-initialize at runtime.
loadCaches()
protected abstract java.util.Collection<? extends Cache> loadCaches()
Called by afterPropertiesSet()
on startup.
The returned collection may be empty but must not be null
.
@Nullable 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
@Nullable protected final Cache lookupCache(java.lang.String name)
getCache(String)
, this method does not trigger
the lazy creation of missing caches via getMissingCache(String)
.name
- the cache identifier (must not be null
)null
if none foundgetCache(String)
,
getMissingCache(String)
@Deprecated protected final void addCache(Cache cache)
getMissingCache(String)
cache
- the Cache to registerprivate void updateCacheNames(java.lang.String name)
cacheNames
set with the given name.
This will always be called within a full cacheMap
lock
and effectively behaves like a CopyOnWriteArraySet
with
preserved order but exposed as an unmodifiable reference.
name
- the name of the cache to be addedprotected Cache decorateCache(Cache cache)
cache
- the Cache object to be added to this CacheManager@Nullable protected Cache getMissingCache(java.lang.String name)
name
or null
if
such cache does not exist or could not be created on the fly.
Some caches may be created at runtime if the native provider supports it. If a lookup by name does not yield any result, a subclass gets a chance to register such a cache at runtime. The returned cache will be automatically added to this instance.
name
- the name of the cache to retrievenull
if no such cache exists or could be
createdgetCache(String)