org.shiftone.cache.policy
Class AbstractPolicyCache

java.lang.Object
  extended byorg.shiftone.cache.policy.AbstractPolicyCache
All Implemented Interfaces:
Cache, ReapableCache
Direct Known Subclasses:
FifoCache, LfuCache, LruCache

public abstract class AbstractPolicyCache
extends java.lang.Object
implements ReapableCache

Class AbstractPolicyCache

Version:
$Revision: 1.1 $
Author:
Jeff Drost

Field Summary
static int SHRINK_DIV
           
 
Constructor Summary
protected AbstractPolicyCache(java.lang.String name, long timeoutMilliSeconds, int maxSize, EvictionListener evictionListener)
           
 
Method Summary
 void addObject(java.lang.Object key, java.lang.Object cacheObject)
          adds an object to the cache
 void clear()
          This method calls shrinkToSize(0) which will loop through each element, removing them one by one (in order of lease valued to most valued).
protected abstract  CacheNode createNode(java.lang.Object key, java.lang.Object cacheObject)
          Create a new node.
protected abstract  void delete(CacheNode node)
          Remove a node from the cache.
protected abstract  CacheNode findNodeByKey(java.lang.Object key)
          Method findNodeByKey
protected abstract  CacheNode getLeastValuableNode()
          This method will execute the cache's onEviction strategy.
protected  int getMaxSize()
           
protected  java.lang.String getName()
           
 java.lang.Object getObject(java.lang.Object key)
          gets the value stored in the cache by it's key, or null if the key is not found.
protected  long getTimeoutMilliSeconds()
           
 void remove(java.lang.Object key)
          remove a specific key/value pair from the cache
abstract  void removeExpiredElements()
          Purge the cache of expired elements.
protected abstract  void revalueNode(CacheNode node)
          Update the node's value.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.shiftone.cache.Cache
size
 

Field Detail

SHRINK_DIV

public static final int SHRINK_DIV
See Also:
Constant Field Values
Constructor Detail

AbstractPolicyCache

protected AbstractPolicyCache(java.lang.String name,
                              long timeoutMilliSeconds,
                              int maxSize,
                              EvictionListener evictionListener)
Method Detail

addObject

public final void addObject(java.lang.Object key,
                            java.lang.Object cacheObject)
Description copied from interface: Cache
adds an object to the cache

Specified by:
addObject in interface Cache

getObject

public final java.lang.Object getObject(java.lang.Object key)
Description copied from interface: Cache
gets the value stored in the cache by it's key, or null if the key is not found.

Specified by:
getObject in interface Cache

remove

public final void remove(java.lang.Object key)
Description copied from interface: Cache
remove a specific key/value pair from the cache

Specified by:
remove in interface Cache

getName

protected java.lang.String getName()

getMaxSize

protected final int getMaxSize()

getTimeoutMilliSeconds

protected final long getTimeoutMilliSeconds()

clear

public void clear()
This method calls shrinkToSize(0) which will loop through each element, removing them one by one (in order of lease valued to most valued). Derived classes may wish to implement this in a more efficient way (by just reinitalizing itself).

Specified by:
clear in interface Cache

findNodeByKey

protected abstract CacheNode findNodeByKey(java.lang.Object key)
Method findNodeByKey


revalueNode

protected abstract void revalueNode(CacheNode node)
Update the node's value. This is done immediately after the node is retrieved.


delete

protected abstract void delete(CacheNode node)
Remove a node from the cache.


getLeastValuableNode

protected abstract CacheNode getLeastValuableNode()
This method will execute the cache's onEviction strategy. If this method is called, there will be at least one element in the cache to remove. The method itself does not need to check for the existance of a element.

This method is only called by shrinkToSize();


removeExpiredElements

public abstract void removeExpiredElements()
Purge the cache of expired elements.

Specified by:
removeExpiredElements in interface ReapableCache

createNode

protected abstract CacheNode createNode(java.lang.Object key,
                                        java.lang.Object cacheObject)
Create a new node.


toString

public java.lang.String toString()