Keel 2.1RC2

org.keel.services.cache.excalibur
Class ConfigurableCache

java.lang.Object
  extended byorg.keel.services.cache.excalibur.ConfigurableCache
All Implemented Interfaces:
Cache, Configurable, LogEnabled

public class ConfigurableCache
extends java.lang.Object
implements Configurable, LogEnabled, Cache

Configurable Cache Component. An extended version of the TimeMapLRUCache implementation from Excalibur that adds configuration capabilities.

Author:
Michael Nash, Leo Simons

Field Summary
private  Logger log
           
private  TimeMapLRUCache myCache
           
 
Fields inherited from interface org.keel.services.cache.Cache
ROLE
 
Constructor Summary
ConfigurableCache()
          A no-op constructor.
ConfigurableCache(Logger log, int cacheSize)
          A constructor that accepts all dependencies and configuration as arguments.
 
Method Summary
 void addListener(CacheListener listener)
           
 void addObject(java.lang.String key, java.lang.Object value)
          Adds an object to the cache.
 int capacity()
           
 void clear()
           
 void configure(Configuration configuration)
          Pass the Configuration to the Configurable class.
 void enableLogging(Logger logger)
          Provide component with a logger.
 void flushCache()
          Flush the cache of all objects.
 java.lang.Object get(java.lang.Object key)
           
 int getCacheSize()
          Returns the current size of the cache.
 int getNumberOfObjects()
          Returns the number of objects in the cache.
 java.lang.Object getObject(java.lang.String key)
          Gets a cached object given its id (a String).
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void removeListener(CacheListener listener)
           
 void removeObject(java.lang.String s)
          Removes an object from the cache.
 void setCacheSize(int cacheSize)
          Set the desired size of the backing cache.
 void setLog(Logger log)
          Set the logger to use for debugging.
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private Logger log

myCache

private TimeMapLRUCache myCache
Constructor Detail

ConfigurableCache

public ConfigurableCache()
A no-op constructor. If you call this constructor, you should call the avalon lifecycle methods as well, or alternatively the appropriate setXXX() methods.


ConfigurableCache

public ConfigurableCache(Logger log,
                         int cacheSize)
A constructor that accepts all dependencies and configuration as arguments. If you call this constructor with non-null arguments, you do not need to call the avalon lifecycle methods or the related setXXX() methods.

Parameters:
log - the logger we'll use for debugging.
cacheSize - the desired size of the backing cache.
Method Detail

setLog

public void setLog(Logger log)
Set the logger to use for debugging.

Parameters:
log - the logger to use for debugging.

setCacheSize

public void setCacheSize(int cacheSize)
Set the desired size of the backing cache.

Parameters:
cacheSize - the desired size of the backing cache.

configure

public void configure(Configuration configuration)
               throws ConfigurationException
Description copied from interface: Configurable
Pass the Configuration to the Configurable class.

Specified by:
configure in interface Configurable
Parameters:
configuration - the class configurations. Must not be null.
Throws:
ConfigurationException - if an error occurs
See Also:
Configurable.configure(Configuration)

enableLogging

public void enableLogging(Logger logger)
Description copied from interface: LogEnabled
Provide component with a logger.

Specified by:
enableLogging in interface LogEnabled
Parameters:
logger - the logger. Must not be null.
See Also:
LogEnabled.enableLogging(Logger)

removeObject

public void removeObject(java.lang.String s)
Description copied from interface: Cache
Removes an object from the cache.

Specified by:
removeObject in interface Cache
Parameters:
s - The String id for the object.

getNumberOfObjects

public int getNumberOfObjects()
Description copied from interface: Cache
Returns the number of objects in the cache.

Specified by:
getNumberOfObjects in interface Cache
Returns:
int The current number of objects in the cache.

capacity

public int capacity()

removeListener

public void removeListener(CacheListener listener)

size

public int size()

addListener

public void addListener(CacheListener listener)

clear

public void clear()

flushCache

public void flushCache()
Description copied from interface: Cache
Flush the cache of all objects.

Specified by:
flushCache in interface Cache

getCacheSize

public int getCacheSize()
Description copied from interface: Cache
Returns the current size of the cache.

Specified by:
getCacheSize in interface Cache
Returns:
int representing current cache size in number of bytes

getObject

public java.lang.Object getObject(java.lang.String key)
Description copied from interface: Cache
Gets a cached object given its id (a String).

Specified by:
getObject in interface Cache
Parameters:
key - The String id for the object.
Returns:
A CachedObject.

get

public java.lang.Object get(java.lang.Object key)

addObject

public void addObject(java.lang.String key,
                      java.lang.Object value)
Description copied from interface: Cache
Adds an object to the cache.

Specified by:
addObject in interface Cache
Parameters:
key - The String id for the object.
value - The object to add to the cache.

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)

Keel 2.1RC2

Please see keelframework.org for information about new Keel releases.