Package org.ehcache

Interface CacheManager

All Superinterfaces:
AutoCloseable, Closeable
All Known Subinterfaces:
PersistentCacheManager

public interface CacheManager extends Closeable
A repository that manages Caches and associated Services.
  • Method Details

    • createCache

      <K, V> Cache<K,V> createCache(String alias, CacheConfiguration<K,V> config)
      Creates a Cache in this CacheManager according to the specified CacheConfiguration.

      The returned Cache will be in status AVAILABLE.

      Type Parameters:
      K - the key type for the cache
      V - the value type for the cache
      Parameters:
      alias - the alias under which the cache will be created
      config - the configuration of the cache to create
      Returns:
      the created and available Cache
      Throws:
      IllegalArgumentException - if there is already a cache registered with the given alias
      IllegalStateException - if the cache creation fails
    • createCache

      <K, V> Cache<K,V> createCache(String alias, Builder<? extends CacheConfiguration<K,V>> configBuilder)
      Creates a Cache in this CacheManager according to the specified CacheConfiguration provided through a Builder.

      The returned Cache will be in status AVAILABLE.

      Type Parameters:
      K - the key type for the cache
      V - the value type for the cache
      Parameters:
      alias - the alias under which the cache will be created
      configBuilder - the builder for the configuration of the cache to create
      Returns:
      the created and available Cache
      Throws:
      IllegalArgumentException - if there is already a cache registered with the given alias
      IllegalStateException - if the cache creation fails
    • getCache

      <K, V> Cache<K,V> getCache(String alias, Class<K> keyType, Class<V> valueType)
      Retrieves the Cache associated with the given alias, if one is known.
      Type Parameters:
      K - the key type for the cache
      V - the value type for the cache
      Parameters:
      alias - the alias under which to look the Cache up
      keyType - the Cache key class
      valueType - the Cache value class
      Returns:
      the Cache associated with the given alias, null if no such cache exists
      Throws:
      IllegalArgumentException - if the keyType or valueType do not match the ones with which the Cache was created
    • removeCache

      void removeCache(String alias)
      Removes the Cache associated with the alias provided, if one is known.

      When the cache is removed, it will release all resources it used.

      Parameters:
      alias - the alias for which to remove the Cache
    • init

      void init() throws StateTransitionException
      Transitions this CacheManager to AVAILABLE.

      This will start all Services managed by this CacheManager, as well as initializing all Caches registered with it.

      If an error occurs before the CacheManager is AVAILABLE, it will revert to UNINITIALIZED attempting to close all services it had already started.

      Throws:
      IllegalStateException - if the CacheManager is not UNINITIALIZED
      StateTransitionException - if the CacheManager could not be made AVAILABLE
    • close

      void close() throws StateTransitionException
      Transitions this CacheManager to UNINITIALIZED.

      This will close all Caches known to this CacheManager and stop all Services managed by this CacheManager.

      Failure to close any Cache or to stop any Service will not prevent others from being closed or stopped.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      StateTransitionException - if the CacheManager could not reach UNINITIALIZED cleanly
      IllegalStateException - if the CacheManager is not AVAILABLE
    • getStatus

      Status getStatus()
      Returns the current Status of this CacheManager.
      Returns:
      the current Status
    • getRuntimeConfiguration

      Configuration getRuntimeConfiguration()
      Returns the current Configuration used by this CacheManager.
      Returns:
      the configuration instance backing this CacheManager