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

public abstract Class AbstractCacheManager

extends Object
implements CacheManager, InitializingBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.InitializingBean, org.springframework.cache.CacheManager
Known Direct Subclasses
org.springframework.cache.support.SimpleCacheManager
Imports
java.util.Collection, .Collections, .LinkedHashSet, .Set, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, org.springframework.beans.factory.InitializingBean, org.springframework.cache.Cache, .CacheManager, org.springframework.lang.Nullable

Abstract base class implementing the common CacheManager methods. Useful for 'static' environments where the backing caches do not change.
Authors
Costin Leau, Juergen Hoeller, Stephane Nicoll
Since
3.1

Field Summary

Modifier and TypeField and Description
private final ConcurrentMap<String, Cache>
private volatile Set<String>

Constructor Summary

AccessConstructor and Description
public

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.

protected Cache

Returns:

the decorated Cache object to be used instead, or simply the passed-in Cache object by default
decorateCache
(Cache
the Cache object to be added to this CacheManager
cache
)

Decorate the given Cache object if necessary.

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.

protected Cache

Returns:

the missing cache, or null if no such cache exists or could be created on demand
getMissingCache
(String
the name of the cache to retrieve
name
)

Return a missing cache with the specified name, or null if such a cache does not exist or could not be created on demand.

public void
initializeCaches()

Initialize the static configuration of caches.

protected abstract Collection<? extends Cache>
loadCaches()

Load the initial caches for this cache manager.

protected final Cache

Returns:

the associated Cache instance, or null if none found
lookupCache
(String
the cache identifier (must not be null)
name
)

Check for a registered cache of the given name.

private void
updateCacheNames(String
the name of the cache to be added
name
)

Update the exposed cacheNames set with the given name.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheMapback to summary
private final ConcurrentMap<String, Cache> cacheMap
cacheNamesback to summary
private volatile Set<String> cacheNames

Constructor Detail

AbstractCacheManagerback to summary
public AbstractCacheManager()

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
decorateCacheback to summary
protected Cache decorateCache(Cache cache)

Decorate the given Cache object if necessary.

Parameters
cache:Cache

the Cache object to be added to this CacheManager

Returns:Cache

the decorated Cache object to be used instead, or simply the passed-in Cache object by default

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
getMissingCacheback to summary
protected Cache getMissingCache(String name)

Return a missing cache with the specified name, or null if such a cache does not exist or could not be created on demand.

Caches may be lazily created at runtime if the native provider supports it. If a lookup by name does not yield any result, an AbstractCacheManager subclass gets a chance to register such a cache at runtime. The returned cache will be automatically added to this cache manager.

Parameters
name:String

the name of the cache to retrieve

Returns:Cache

the missing cache, or null if no such cache exists or could be created on demand

Annotations
@Nullable
Since
4.1
See Also
getCache(String)
initializeCachesback to summary
public void initializeCaches()

Initialize the static configuration of caches.

Triggered on startup through afterPropertiesSet(); can also be called to re-initialize at runtime.

Since
4.2.2
See Also
loadCaches()
loadCachesback to summary
protected abstract Collection<? extends Cache> loadCaches()

Load the initial caches for this cache manager.

Called by afterPropertiesSet() on startup. The returned collection may be empty but must not be null.

lookupCacheback to summary
protected final Cache lookupCache(String name)

Check for a registered cache of the given name. In contrast to getCache(String), this method does not trigger the lazy creation of missing caches via getMissingCache(String).

Parameters
name:String

the cache identifier (must not be null)

Returns:Cache

the associated Cache instance, or null if none found

Annotations
@Nullable
Since
4.1
See Also
getCache(String), getMissingCache(String)
updateCacheNamesback to summary
private void updateCacheNames(String name)

Update the exposed 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.

Parameters
name:String

the name of the cache to be added