Class AbstractCacheManager

java.lang.Object
org.apache.shiro.cache.AbstractCacheManager
All Implemented Interfaces:
CacheManager, org.apache.shiro.lang.util.Destroyable
Direct Known Subclasses:
MemoryConstrainedCacheManager

public abstract class AbstractCacheManager extends Object implements CacheManager, org.apache.shiro.lang.util.Destroyable
Very simple abstract CacheManager implementation that retains all created Cache instances in an in-memory ConcurrentMap. Cache instance creation is left to subclasses via the createCache method implementation.
Since:
1.0
  • Constructor Details

    • AbstractCacheManager

      Default no-arg constructor that instantiates an internal name-to-cache ConcurrentMap.
  • Method Details

    • getCache

      public <K, V> Cache<K,V> getCache(String name) throws IllegalArgumentException, CacheException
      Returns the cache with the specified name. If the cache instance does not yet exist, it will be lazily created, retained for further access, and then returned.
      Specified by:
      getCache in interface CacheManager
      Parameters:
      name - the name of the cache to acquire.
      Returns:
      the cache with the specified name.
      Throws:
      IllegalArgumentException - if the name argument is null or does not contain text.
      CacheException - if there is a problem lazily creating a Cache instance.
    • createCache

      protected abstract <K, V> Cache<K,V> createCache(String name) throws CacheException
      Creates a new Cache instance associated with the specified name.
      Parameters:
      name - the name of the cache to create
      Returns:
      a new Cache instance associated with the specified name.
      Throws:
      CacheException - if the Cache instance cannot be created.
    • destroy

      public void destroy() throws Exception
      Cleanup method that first destroys all of it's managed caches and then clears out the internally referenced cache map.
      Specified by:
      destroy in interface org.apache.shiro.lang.util.Destroyable
      Throws:
      Exception - if any of the managed caches can't destroy properly.
    • toString

      public String toString()
      Overrides:
      toString in class Object