org.apache.jcs.engine.memory
Class AbstractMemoryCache

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

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

Some common code for the LRU and MRU 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
 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
          The region name.
 ICompositeCacheAttributes cattr
          Cache Attributes
protected  int chunkSize
          How many to spool at a time.
protected  java.util.Map map
          Map where items are stored by key
protected  int status
          status
 
Constructor Summary
AbstractMemoryCache()
           
 
Method Summary
abstract  java.util.Map createMap()
          Children must implement this method.
 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 that 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
 java.util.Map getMultiple(java.util.Set keys)
          Gets multiple items from the cache based on the given set of keys.
 ICacheElement getQuiet(java.io.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(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
 
Methods inherited from interface org.apache.jcs.engine.memory.behavior.IMemoryCache
freeElements
 

Field Detail

cacheName

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


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
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 java.util.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:
Map

remove

public abstract boolean remove(java.io.Serializable key)
                        throws java.io.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:
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 IMemoryCache
Parameters:
key - Description of the Parameter
Returns:
Description of the Return Value
Throws:
java.io.IOException - Description of the Exception

getMultiple

public java.util.Map getMultiple(java.util.Set keys)
                          throws java.io.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:
java.io.IOException

getQuiet

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

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

update

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

Specified by:
update in interface IMemoryCache
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 IMemoryCache
Returns:
An Object[]

removeAll

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

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

dispose

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

Specified by:
dispose in interface IMemoryCache
Throws:
java.io.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 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 IMemoryCache
Parameters:
ce -
Throws:
java.io.IOException

getIterator

public java.util.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 java.util.Set getGroupKeys(java.lang.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-2011 Apache Software Foundation. All Rights Reserved.