net.sf.ehcache
public class CacheManager extends Object
Version: $Id: CacheManager.java 191 2006-09-03 22:41:48Z gregluck $
Field Summary | |
---|---|
static List | ALL_CACHE_MANAGERS
Keeps track of all known CacheManagers. |
protected Map | caches
Caches managed by this manager. |
Constructor Summary | |
---|---|
CacheManager(Configuration configuration)
An constructor for CacheManager, which takes a configuration object, rather than one created by parsing
an ehcache.xml file. | |
CacheManager(String configurationFileName)
An ordinary constructor for CacheManager.
| |
CacheManager(URL configurationURL)
An ordinary constructor for CacheManager.
| |
CacheManager(InputStream configurationInputStream)
An ordinary constructor for CacheManager.
| |
CacheManager()
Constructor.
|
Method Summary | |
---|---|
void | addCache(String cacheName)
Adds a Ehcache based on the defaultCache with the given name.
|
void | addCache(Cache cache)
Adds a Cache to the CacheManager.
|
void | addCache(Ehcache cache)
Adds an Ehcache to the CacheManager.
|
boolean | cacheExists(String cacheName)
Checks whether a cache exists.
|
void | clearAll()
Clears the contents of all caches in the CacheManager, but without
removing any caches.
|
static CacheManager | create()
A factory method to create a singleton CacheManager with default config, or return it if it exists.
|
static CacheManager | create(String configurationFileName)
A factory method to create a singleton CacheManager with a specified configuration.
|
static CacheManager | create(URL configurationFileURL)
A factory method to create a singleton CacheManager from an URL.
|
static CacheManager | create(InputStream inputStream)
A factory method to create a singleton CacheManager from a java.io.InputStream.
|
Cache | getCache(String name)
Returns a concrete implementation of Cache.
|
CacheManagerEventListener | getCacheManagerEventListener()
Gets the CacheManager event listener.
|
CacheManagerPeerProvider | getCacheManagerPeerProvider()
Gets the CacheManagerPeerProvider, which can be useful for programmatically adding peers. |
String[] | getCacheNames()
Returns a list of the current cache names.
|
CacheManagerPeerListener | getCachePeerListener()
When CacheManage is configured as part of a cluster, a CacheManagerPeerListener will
be registered in it. |
CacheManagerPeerProvider | getCachePeerProvider()
Gets the CacheManagerPeerProvider
For distributed caches, the peer provider finds other cache managers and their caches in the same cluster
|
Ehcache | getEhcache(String name)
Gets an Ehcache
|
static CacheManager | getInstance()
A factory method to create a singleton CacheManager with default config, or return it if it exists.
|
Status | getStatus()
Gets the status attribute of the Ehcache
|
void | removalAll()
Removes all caches using CacheManager for each cache. |
void | removeCache(String cacheName)
Remove a cache from the CacheManager. |
void | replaceCacheWithDecoratedCache(Ehcache cache, Ehcache decoratedCache)
Replaces in the map of Caches managed by this CacheManager an Ehcache with a decorated version of the same
Ehcache. |
void | setCacheManagerEventListener(CacheManagerEventListener cacheManagerEventListener)
Sets the CacheManager event listener. |
void | shutdown()
Shuts down the CacheManager.
|
Parameters: configuration
Throws: CacheException
Parameters: configurationFileName an xml configuration file available through a file name. The configuration
File is created
using new File(configurationFileName)
Throws: CacheException
See Also: create
URL url = this.getClass().getResource("/ehcache-2.xml");Note that Class#getResource will look for resources in the same package unless a leading "/" is used, in which case it will look in the root of the classpath. You can also load a resource using other class loaders. e.g. Thread#getContextClassLoader()
Parameters: configurationURL an xml configuration available through a URL.
Throws: CacheException
Since: 1.2
See Also: create
Parameters: configurationInputStream an xml configuration file available through an inputstream
Throws: CacheException
See Also: create
Throws: CacheException
Parameters: cacheName the name for the cache
Throws: ObjectExistsException if the cache already exists CacheException if there was an error creating the cache.
Parameters: cache
Throws: IllegalStateException if the cache is not STATUS_UNINITIALISED before this method is called. ObjectExistsException if the cache already exists in the CacheManager CacheException if there was an error adding the cache to the CacheManager
Parameters: cache
Throws: IllegalStateException if the cache is not STATUS_UNINITIALISED before this method is called. ObjectExistsException if the cache already exists in the CacheManager CacheException if there was an error adding the cache to the CacheManager
Parameters: cacheName the cache name to check for
Returns: true if it exists
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Returns: the singleton CacheManager
Throws: CacheException if the CacheManager cannot be created
Parameters: configurationFileName an xml file compliant with the ehcache.xsd schema The configuration will be read, Ehcaches created and required stores initialized. When the CacheManager is no longer required, call shutdown to free resources.
URL url = this.getClass().getResource("/ehcache-2.xml");Note that Class#getResource will look for resources in the same package unless a leading "/" is used, in which case it will look in the root of the classpath. You can also load a resource using other class loaders. e.g. Thread#getContextClassLoader()
Parameters: configurationFileURL an URL to an xml file compliant with the ehcache.xsd schema The configuration will be read, Ehcaches created and required stores initialized. When the CacheManager is no longer required, call shutdown to free resources.
Parameters: inputStream InputStream of xml compliant with the ehcache.xsd schema The configuration will be read, Ehcaches created and required stores initialized. When the CacheManager is no longer required, call shutdown to free resources.
Throws: IllegalStateException if the cache is not STATUS_ALIVE ClassCastException is the Ehcache found is not a Cache
Returns: null if none
Returns: the CacheManagerPeerProvider, or null if there is not one.
Returns: an array of Strings
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Returns: the listener, or null if one does not exist
CacheManagerPeerProvider
For distributed caches, the peer provider finds other cache managers and their caches in the same cluster
Returns: the provider, or null if one does not exist
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Returns: the singleton CacheManager
Throws: CacheException if the CacheManager cannot be created
Returns: The status value from the Status enum class
Parameters: cacheName the cache name
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Parameters: cache decoratedCache An implementation of Ehcache that wraps the original cache.
Throws: CacheException if the two caches do not equal each other.
Parameters: cacheManagerEventListener the listener to set.