com.compoundtheory.objectcache
Class ObjectCache

java.lang.Object
  extended by java.util.Observable
      extended by com.compoundtheory.objectcache.ObjectCache

public class ObjectCache
extends java.util.Observable

Object for persisting ColdFusion CFCs

Author:
Mark Mandel

Field Summary
static java.lang.String CLEAR_CFC_KEY
           
static java.lang.String CLEAR_SOFTREF_KEY
           
 
Constructor Summary
ObjectCache(java.lang.String className, edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor threadPool)
          Default constructor of unlimited objects, and always persisted
ObjectCache(java.lang.String className, edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor threadPool, Config config)
          Constructor for a new Object Cache
 
Method Summary
 void add(java.lang.ref.SoftReference softRef, java.lang.String key)
          Adds an object to the cache
 void discard(java.lang.String key)
          discard a key from the cache
 java.lang.Object get(java.lang.String key)
          Retrieve an object from the cache
 int getCalculatedSize()
          Returns the calculated size (slow), by looping through a copy of the collection and checking if the soft references are cleared or not
 int getEstimatedSize()
          Returns the estimate size of the cache (fast), does not scan the cache for empty soft references
 boolean has(java.lang.String key)
          If the cache has the object, and it hasn't expired
 void reap(java.lang.ref.SoftReference softRef)
          Reaps out the soft ref required
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLEAR_CFC_KEY

public static final java.lang.String CLEAR_CFC_KEY
See Also:
Constant Field Values

CLEAR_SOFTREF_KEY

public static final java.lang.String CLEAR_SOFTREF_KEY
See Also:
Constant Field Values
Constructor Detail

ObjectCache

public ObjectCache(java.lang.String className,
                   edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor threadPool)
            throws InvalidScopeException
Default constructor of unlimited objects, and always persisted

Throws:
InvalidScopeException

ObjectCache

public ObjectCache(java.lang.String className,
                   edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor threadPool,
                   Config config)
Constructor for a new Object Cache

Parameters:
className - the name of the class that this cache represents
threadPool - the thread pool
config - the configuration for this cache.
Method Detail

has

public boolean has(java.lang.String key)
If the cache has the object, and it hasn't expired

Parameters:
key - The key to look for the object is stored under
Returns:
whether the object exists, and hasn't expired

get

public java.lang.Object get(java.lang.String key)
                     throws ObjectNotFoundException
Retrieve an object from the cache

Parameters:
key - The key to look for
Returns:
The CFC that was stored in here
Throws:
ObjectNotFoundException - If the object doesn't exist in the cache, this is thrown

add

public void add(java.lang.ref.SoftReference softRef,
                java.lang.String key)
Adds an object to the cache

Parameters:
softRef - the soft reference that contains the object
key - The key to store it under. This should be unique

discard

public void discard(java.lang.String key)
discard a key from the cache

Parameters:
key - the key to discard

reap

public void reap(java.lang.ref.SoftReference softRef)
Reaps out the soft ref required

Parameters:
softRef - the soft ref that has been cleared

getEstimatedSize

public int getEstimatedSize()
Returns the estimate size of the cache (fast), does not scan the cache for empty soft references

Returns:
the estimated cache size

getCalculatedSize

public int getCalculatedSize()
Returns the calculated size (slow), by looping through a copy of the collection and checking if the soft references are cleared or not

Returns:
the calculated cache size