org.apache.jcs.engine.memory
Class AbstractMemoryCache

java.lang.Object
  extended byorg.apache.jcs.engine.memory.AbstractMemoryCache
All Implemented Interfaces:
MemoryCache, java.io.Serializable
Direct Known Subclasses:
LRUMemoryCache, MRUMemoryCache

public abstract class AbstractMemoryCache
extends java.lang.Object
implements MemoryCache, java.io.Serializable

Some common code for the LRU and MRU caches.

Version:
$Id: AbstractMemoryCache.java,v 1.5 2003/08/22 11:57:18 mpoeschl Exp $
Author:
Aaron Smuts, James Taylor, John McNally
See Also:
Serialized Form

Field Summary
 IElementAttributes attr
          Region Elemental Attributes, used as a default.
protected  CompositeCache cache
          The cache region this store is associated with
protected  java.lang.String cacheName
           
 ICompositeCacheAttributes cattr
          Cache Attributes
protected  int chunkSize
           
private static org.apache.commons.logging.Log log
           
protected  java.util.Map map
          Map where items are stored by key
private  ShrinkerThread shrinker
          The background memory shrinker
protected  int status
           
 
Constructor Summary
AbstractMemoryCache()
          Constructor for the LRUMemoryCache object
 
Method Summary
 void dispose()
          Prepares for shutdown.
abstract  ICacheElement get(java.io.Serializable key)
          Get an item from the cache
 ICompositeCacheAttributes getCacheAttributes()
          Returns the CacheAttributes.
 java.lang.String getCacheName()
          Returns the cache name.
 CompositeCache getCompositeCache()
          Gets the cache hub / region taht the MemoryCache is used by
 java.util.Set getGroupKeys(java.lang.String groupName)
          Gets the set of keys of objects currently in the group
 java.util.Iterator getIterator()
          Gets the iterator attribute of the LRUMemoryCache object
abstract  java.lang.Object[] getKeyArray()
          Get an Array of the keys for all elements in the memory cache
abstract  ICacheElement getQuiet(java.io.Serializable key)
          Get an item from the cache without effecting its order or last access time
 int getSize()
          Returns the current cache size.
 java.lang.String getStats()
          Returns the cache statistics.
 int getStatus()
          Returns the cache status.
 void initialize(CompositeCache hub)
          For post reflection creation initialization
abstract  boolean remove(java.io.Serializable key)
          Removes an item from the cache
 void removeAll()
          Removes all cached items from the cache.
 void setCacheAttributes(ICompositeCacheAttributes cattr)
          Sets the CacheAttributes.
abstract  void update(ICacheElement ce)
          Puts an item to the cache.
 void waterfal(ICacheElement ce)
          Puts an item to the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.commons.logging.Log log

cacheName

protected java.lang.String cacheName

map

protected java.util.Map map
Map where items are stored by key


attr

public IElementAttributes attr
Region Elemental Attributes, used as a default.


cattr

public ICompositeCacheAttributes cattr
Cache Attributes


cache

protected CompositeCache cache
The cache region this store is associated with


status

protected int status

chunkSize

protected int chunkSize

shrinker

private ShrinkerThread shrinker
The background memory shrinker

Constructor Detail

AbstractMemoryCache

public AbstractMemoryCache()
Constructor for the LRUMemoryCache object

Method Detail

initialize

public void initialize(CompositeCache hub)
For post reflection creation initialization

Specified by:
initialize in interface MemoryCache
Parameters:
hub -

remove

public abstract boolean remove(java.io.Serializable key)
                        throws java.io.IOException
Removes an item from the cache

Specified by:
remove in interface MemoryCache
Parameters:
key - Identifies item to be removed
Returns:
Description of the Return Value
Throws:
java.io.IOException - Description of the Exception

get

public abstract ICacheElement get(java.io.Serializable key)
                           throws java.io.IOException
Get an item from the cache

Specified by:
get in interface MemoryCache
Parameters:
key - Description of the Parameter
Returns:
Description of the Return Value
Throws:
java.io.IOException - Description of the Exception

getQuiet

public abstract ICacheElement getQuiet(java.io.Serializable key)
                                throws java.io.IOException
Get an item from the cache without effecting its order or last access time

Specified by:
getQuiet in interface MemoryCache
Parameters:
key - Description of the Parameter
Returns:
The quiet value
Throws:
java.io.IOException - Description of the Exception

update

public abstract void update(ICacheElement ce)
                     throws java.io.IOException
Puts an item to the cache.

Specified by:
update in interface MemoryCache
Parameters:
ce - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception

getKeyArray

public abstract java.lang.Object[] getKeyArray()
Get an Array of the keys for all elements in the memory cache

Specified by:
getKeyArray in interface MemoryCache
Returns:
An Object[]

removeAll

public void removeAll()
               throws java.io.IOException
Removes all cached items from the cache.

Specified by:
removeAll in interface MemoryCache
Throws:
java.io.IOException

dispose

public void dispose()
             throws java.io.IOException
Prepares for shutdown.

Throws:
java.io.IOException

getStats

public java.lang.String getStats()
Returns the cache statistics.

Returns:
The stats value

getSize

public int getSize()
Returns the current cache size.

Specified by:
getSize in interface MemoryCache
Returns:
The size value

getStatus

public int getStatus()
Returns the cache status.

Returns:
The status value

getCacheName

public java.lang.String getCacheName()
Returns the cache name.

Returns:
The cacheName value

waterfal

public void waterfal(ICacheElement ce)
              throws java.io.IOException
Puts an item to the cache.

Specified by:
waterfal in interface MemoryCache
Parameters:
ce - Description of the Parameter
Throws:
java.io.IOException

getIterator

public java.util.Iterator getIterator()
Gets the iterator attribute of the LRUMemoryCache object

Specified by:
getIterator in interface MemoryCache
Returns:
The iterator value

getCacheAttributes

public ICompositeCacheAttributes getCacheAttributes()
Returns the CacheAttributes.

Specified by:
getCacheAttributes in interface MemoryCache
Returns:
The CacheAttributes value

setCacheAttributes

public void setCacheAttributes(ICompositeCacheAttributes cattr)
Sets the CacheAttributes.

Specified by:
setCacheAttributes in interface MemoryCache
Parameters:
cattr - The new CacheAttributes value

getCompositeCache

public CompositeCache getCompositeCache()
Gets the cache hub / region taht the MemoryCache is used by

Specified by:
getCompositeCache in interface MemoryCache
Returns:
The cache value

getGroupKeys

public java.util.Set getGroupKeys(java.lang.String groupName)
Description copied from interface: MemoryCache
Gets the set of keys of objects currently in the group

Specified by:
getGroupKeys in interface MemoryCache