Package org.apache.wiki.cache

# Class EhcacheCachingManager

java.lang.Object
org.apache.wiki.cache.EhcacheCachingManager

All Implemented Interfaces:
  `Initializable`, `CachingManager`

public class EhcacheCachingManager extends Object implements CachingManager, Initializable
Ehcache-based `CachingManager`.

## Field Summary

### Fields inherited from interface org.apache.wiki.cache.CachingManager

`CACHE_ATTACHMENTS, CACHE_ATTACHMENTS_COLLECTION, CACHE_ATTACHMENTS_DYNAMIC, CACHE_DOCUMENTS, CACHE_PAGES, CACHE_PAGES_HISTORY, CACHE_PAGES_TEXT, PROP_CACHE_CONF_FILE, PROP_CACHE_ENABLE, PROP_USECACHE_DEPRECATED`

## Constructor Summary

Constructors
Constructor
Description
`EhcacheCachingManager()`

## Method Summary

Modifier and Type
Method
Description
`boolean`
`enabled(String cacheName)`
Checks if the requested cache is enabled or not.
`<T, E extends Exception>
T`
`get(String cacheName, Serializable key, CheckedSupplier<T,E> supplier)`
Returns an item from a cache.
`CacheInfo`
`info(String cacheName)`
Retrieves cache usage information.
`void`
`initialize(Engine engine, Properties props)`
`List<String>`
`keys(String cacheName)`
Returns the list of keys from elements present in a cache.
`void`
`put(String cacheName, Serializable key, Object val)`
Puts an item on a cache.
`boolean`
`registerListener(String cacheName, String listener, Object... args)`
Register a listener associated with the given cache and type of listener.
`void`
`remove(String cacheName, Serializable key)`
Removes an item from a cache.
`void`
`shutdown()`
Shuts down the underlying cache manager

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### EhcacheCachingManager

public EhcacheCachingManager()

## Method Details

### shutdown

public void shutdown()
Shuts down the underlying cache manager

Specified by:
  `shutdown` in interface `CachingManager`

### initialize

public void initialize(Engine engine, Properties props) throws WikiException

Specified by:
  `initialize` in interface `Initializable`
Throws:
  `WikiException`

### enabled

public boolean enabled(String cacheName)
Checks if the requested cache is enabled or not.

Specified by:
  `enabled` in interface `CachingManager`
Parameters:
  `cacheName` - The cache to be queried.
Returns:
  `true` if the cache is enabled, `false` otherwise.

### info

public CacheInfo info(String cacheName)
Retrieves cache usage information.

Specified by:
  `info` in interface `CachingManager`
Parameters:
  `cacheName` - The cache to be queried.
Returns:
  cache usage information, or `null` if the requested cache is not enabled.

### keys

public List<String> keys(String cacheName)
Returns the list of keys from elements present in a cache.

Specified by:
  `keys` in interface `CachingManager`
Parameters:
  `cacheName` - The cache to be queried.
Returns:
  list of keys from elements present in a cache.

### get

public <T, E extends Exception> T get(String cacheName, Serializable key, CheckedSupplier<T,E> supplier) throws E
Returns an item from a cache. If it is not found on the cache, try to retrieve from the provided supplier. If found there, put the value in the cache, and return it. Otherwise, return `null`.

Specified by:
  `get` in interface `CachingManager`
Parameters:
  `cacheName` - The cache in which the item lives.
  `key` - item's identifier.
  `supplier` - if the element is not cached, try to retrieve from the cached system.
Returns:
  The requested item or `null` if either the cache is not enabled or the item is not present on the cache / cached service.
Throws:
  `E` - the supplier may throw a checked exception, which is propagated upwards.

### put

public void put(String cacheName, Serializable key, Object val)
Puts an item on a cache.

Specified by:
  `put` in interface `CachingManager`
Parameters:
  `cacheName` - The cache in which the item will live.
  `key` - item's identifier.
  `val` - item to insert in the cache.

### remove

public void remove(String cacheName, Serializable key)
Removes an item from a cache.

Specified by:
  `remove` in interface `CachingManager`
Parameters:
  `cacheName` - The cache in which the item to be removed lives.
  `key` - item's identifier.

### registerListener

public boolean registerListener(String cacheName, String listener, Object... args)
Register a listener associated with the given cache and type of listener.

Specified by:
  `registerListener` in interface `CachingManager`
Parameters:
  `cacheName` - the name of the cache where the listener will be registered.
  `listener` - the kind of listener to be registered
  `args` - arguments needed to instantiate and register the listener.
Returns:
  `true` if the listener is created & registered, `false` otherwise.