org.apache.jcs.engine.memory
Class AbstractMemoryCache

java.lang.Object
  extended by org.apache.jcs.engine.memory.AbstractMemoryCache
All Implemented Interfaces:
Serializable, IMemoryCache, MemoryCache
Direct Known Subclasses:
AbstractDoulbeLinkedListMemoryCache, LHMLRUMemoryCache

public abstract class AbstractMemoryCache
extends Object
implements MemoryCache, Serializable

This base includes some common code for memory caches.

This keeps a static reference to a memory shrinker clock daemon. If this region is configured to use the shrinker, the clock daemon will be setup to run the shrinker on this region.

See Also:
Serialized Form

Field Summary
protected  CompositeCache cache
          The cache region this store is associated with
 ICompositeCacheAttributes cacheAttributes
          Cache Attributes.
protected  String cacheName
          The region name.
protected  int chunkSize
          How many to spool at a time.
 IElementAttributes elementAttributes
          Region Elemental Attributes, used as a default and copied for each item.
protected  Map map
          Map where items are stored by key.
protected  int status
          status
 
Constructor Summary
AbstractMemoryCache()
           
 
Method Summary
abstract  Map createMap()
          Children must implement this method.
 void dispose()
          Prepares for shutdown.
abstract  ICacheElement get(Serializable key)
          Get an item from the cache
 ICompositeCacheAttributes getCacheAttributes()
          Returns the CacheAttributes.
 String getCacheName()
          Returns the cache (aka "region") name.
 CompositeCache getCompositeCache()
          Gets the cache hub / region that the MemoryCache is used by
 Set getGroupKeys(String groupName)
          Gets the set of keys of objects currently in the group.
 Iterator getIterator()
          Gets the iterator attribute of the LRUMemoryCache object
abstract  Object[] getKeyArray()
          Get an Array of the keys for all elements in the memory cache
 Map getMultiple(Set keys)
          Gets multiple items from the cache based on the given set of keys.
 ICacheElement getQuiet(Serializable key)
          Get an item from the cache without affecting its last access time or position.
 int getSize()
          Returns the current cache size.
 IStats getStatistics()
          Returns the historical and statistical data for a region's memory cache.
 int getStatus()
          Returns the cache status.
 void initialize(CompositeCache hub)
          For post reflection creation initialization
abstract  boolean remove(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
 
Methods inherited from interface org.apache.jcs.engine.memory.behavior.IMemoryCache
freeElements
 

Field Detail

cacheName

protected String cacheName
The region name. This defines a namespace of sorts.


map

protected Map map
Map where items are stored by key. This is created by the concrete child class.


elementAttributes

public IElementAttributes elementAttributes
Region Elemental Attributes, used as a default and copied for each item.


cacheAttributes

public ICompositeCacheAttributes cacheAttributes
Cache Attributes. Regions settings.


cache

protected CompositeCache cache
The cache region this store is associated with


status

protected int status
status


chunkSize

protected int chunkSize
How many to spool at a time.

Constructor Detail

AbstractMemoryCache

public AbstractMemoryCache()
Method Detail

initialize

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

Specified by:
initialize in interface IMemoryCache
Parameters:
hub -

createMap

public abstract Map createMap()
Children must implement this method. A FIFO implementation may use a tree map. An LRU might use a hashtable. The map returned should be threadsafe.

Returns:
a threadsafe Map

remove

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

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

get

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

Specified by:
get in interface IMemoryCache
Parameters:
key - Description of the Parameter
Returns:
Description of the Return Value
Throws:
IOException - Description of the Exception

getMultiple

public Map getMultiple(Set keys)
                throws IOException
Gets multiple items from the cache based on the given set of keys.

Specified by:
getMultiple in interface IMemoryCache
Parameters:
keys -
Returns:
a map of Serializable key to ICacheElement element, or an empty map if there is no data in cache for any of these keys
Throws:
IOException

getQuiet

public ICacheElement getQuiet(Serializable key)
                       throws IOException
Get an item from the cache without affecting its last access time or position. Not all memory cache implementations can get quietly.

Specified by:
getQuiet in interface IMemoryCache
Parameters:
key - Identifies item to find
Returns:
Element matching key if found, or null
Throws:
IOException

update

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

Specified by:
update in interface IMemoryCache
Parameters:
ce - Description of the Parameter
Throws:
IOException - Description of the Exception

getKeyArray

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

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

removeAll

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

Specified by:
removeAll in interface IMemoryCache
Throws:
IOException

dispose

public void dispose()
             throws IOException
Prepares for shutdown.

Specified by:
dispose in interface IMemoryCache
Throws:
IOException

getStatistics

public IStats getStatistics()
Description copied from interface: IMemoryCache
Returns the historical and statistical data for a region's memory cache.

Specified by:
getStatistics in interface IMemoryCache
Returns:
statistics about the cache

getSize

public int getSize()
Returns the current cache size.

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

getStatus

public int getStatus()
Returns the cache status.

Returns:
The status value

getCacheName

public String getCacheName()
Returns the cache (aka "region") name.

Returns:
The cacheName value

waterfal

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

Specified by:
waterfal in interface IMemoryCache
Parameters:
ce -
Throws:
IOException

getIterator

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

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

getCacheAttributes

public ICompositeCacheAttributes getCacheAttributes()
Returns the CacheAttributes.

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

setCacheAttributes

public void setCacheAttributes(ICompositeCacheAttributes cattr)
Sets the CacheAttributes.

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

getCompositeCache

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

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

getGroupKeys

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

Specified by:
getGroupKeys in interface IMemoryCache
Parameters:
groupName -
Returns:
group keys


Copyright © 2002-2012 Apache Software Foundation. All Rights Reserved.