Package org.apache.shiro.cache
Class AbstractCacheManager
- java.lang.Object
-
- org.apache.shiro.cache.AbstractCacheManager
-
- All Implemented Interfaces:
CacheManager
,Destroyable
- Direct Known Subclasses:
MemoryConstrainedCacheManager
public abstract class AbstractCacheManager extends Object implements CacheManager, Destroyable
Very simple abstractCacheManager
implementation that retains all createdCache
instances in an in-memoryConcurrentMap
.Cache
instance creation is left to subclasses via thecreateCache
method implementation.- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description AbstractCacheManager()
Default no-arg constructor that instantiates an internal name-to-cacheConcurrentMap
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract Cache
createCache(String name)
Creates a newCache
instance associated with the specifiedname
.void
destroy()
<K,V>
Cache<K,V>getCache(String name)
Returns the cache with the specifiedname
.String
toString()
-
-
-
Constructor Detail
-
AbstractCacheManager
public AbstractCacheManager()
Default no-arg constructor that instantiates an internal name-to-cacheConcurrentMap
.
-
-
Method Detail
-
getCache
public <K,V> Cache<K,V> getCache(String name) throws IllegalArgumentException, CacheException
Returns the cache with the specifiedname
. If the cache instance does not yet exist, it will be lazily created, retained for further access, and then returned.- Specified by:
getCache
in interfaceCacheManager
- Parameters:
name
- the name of the cache to acquire.- Returns:
- the cache with the specified
name
. - Throws:
IllegalArgumentException
- if thename
argument isnull
or does not contain text.CacheException
- if there is a problem lazily creating aCache
instance.
-
createCache
protected abstract Cache createCache(String name) throws CacheException
Creates a newCache
instance associated with the specifiedname
.- Parameters:
name
- the name of the cache to create- Returns:
- a new
Cache
instance associated with the specifiedname
. - Throws:
CacheException
- if theCache
instance cannot be created.
-
destroy
public void destroy() throws Exception
Cleanup method that firstdestroys
all of it's managed caches and thenclears
out the internally referenced cache map.- Specified by:
destroy
in interfaceDestroyable
- Throws:
Exception
- if any of the managed caches can't destroy properly.
-
-