org.apache.manifoldcf.core.cachemanager
Class GeneralCache

java.lang.Object
  extended by org.apache.manifoldcf.core.cachemanager.GeneralCache

public class GeneralCache
extends java.lang.Object

General cache class. This class will be statically instantiated. It contains all the structures needed to maintain a cache of objects, with both LRU flushing behavior, and timed expiration of objects. This cache is entirely local to a JVM and does NOT have any locking and synchronization semantics cross-JVM. That is handled at a higher level.


Nested Class Summary
protected  class GeneralCache.ExpirationTree
          This class represents a timed expiration tree.
protected  class GeneralCache.ExpirationTreeNode
          This class represents a node in the expiration tree.
protected  class GeneralCache.InvalidationTable
          This class describes a table of invalidation keys, each of which points to a set of object records.
protected  class GeneralCache.ObjectClassRecord
          This is a helper class for the ObjectClassTable.
protected  class GeneralCache.ObjectClassTable
          This class describes a set of object classes, each with its own LRU behavior.
protected  class GeneralCache.ObjectRecord
          This class represents a cached object.
protected  class GeneralCache.ObjectRecordTable
          This class describes a table of object records, looked up by the unique object description.
 
Field Summary
static java.lang.String _rcsid
           
 GeneralCache.ExpirationTree expirationTree
           
protected  GeneralCache.ObjectRecordTable hashtable
           
protected  GeneralCache.InvalidationTable invalidationTable
           
protected  GeneralCache.ObjectClassTable objectClassTable
           
 
Constructor Summary
GeneralCache()
           
 
Method Summary
protected  void deleteEntry(GeneralCache.ObjectRecord record)
          Delete a record from the cache.
 void deleteObject(java.lang.Object objectDescription)
          Delete a record from the cache.
 void expireRecords(long expireTime)
          Expire all records that have older expiration times than that passed in.
 long getObjectCreationTime(java.lang.Object objectDescription)
          Get the creation time of an object in the cache.
 StringSet getObjectInvalidationKeys(java.lang.Object objectDescription)
          Get the invalidation keys for an object in the cache.
 void invalidateKeys(StringSet keys)
          Invalidate a set of keys.
 java.lang.Object lookup(java.lang.Object objectDescription)
          Locate an object in the cache, and return it if found.
 void setObject(java.lang.Object objectDescription, java.lang.Object object, StringSet keys, long timestamp)
          Add a newly created object to the cache.
 void setObjectClass(java.lang.Object objectDescription, java.lang.String objectClass, int maxCount)
          Set an object's class and maximum count.
 void setObjectExpiration(java.lang.Object objectDescription, long expirationTime)
          Set an object's expiration time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_rcsid

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

hashtable

protected GeneralCache.ObjectRecordTable hashtable

invalidationTable

protected GeneralCache.InvalidationTable invalidationTable

objectClassTable

protected GeneralCache.ObjectClassTable objectClassTable

expirationTree

public GeneralCache.ExpirationTree expirationTree
Constructor Detail

GeneralCache

public GeneralCache()
Method Detail

lookup

public java.lang.Object lookup(java.lang.Object objectDescription)
Locate an object in the cache, and return it if found.

Parameters:
objectDescription - is the object's unique identifier.
Returns:
the object if found, or null if not present in the cache.

getObjectCreationTime

public long getObjectCreationTime(java.lang.Object objectDescription)
Get the creation time of an object in the cache.

Parameters:
objectDescription - is the object's unique identifier.
Returns:
the creation time, or -1 if object not found.

getObjectInvalidationKeys

public StringSet getObjectInvalidationKeys(java.lang.Object objectDescription)
Get the invalidation keys for an object in the cache.

Parameters:
objectDescription - is the object's unique identifier.
Returns:
the keys, or null if not found.

deleteObject

public void deleteObject(java.lang.Object objectDescription)
Delete a record from the cache.

Parameters:
objectDescription - is the unique description.

setObject

public void setObject(java.lang.Object objectDescription,
                      java.lang.Object object,
                      StringSet keys,
                      long timestamp)
Add a newly created object to the cache. Use ONLY for newly created objects!

Parameters:
objectDescription - is the newly created object's unique description.
object - is the newly created object itself.
keys - are the invalidation keys for the newly created object.
timestamp - is the creation timestamp for this object (used for cross-JVM invalidation)

setObjectExpiration

public void setObjectExpiration(java.lang.Object objectDescription,
                                long expirationTime)
Set an object's expiration time.

Parameters:
objectDescription - is the object's unique description.
expirationTime - is the object's new expiration time, in milliseconds since epoch.

setObjectClass

public void setObjectClass(java.lang.Object objectDescription,
                           java.lang.String objectClass,
                           int maxCount)
Set an object's class and maximum count. This will clean up extra objects in a Least Recently Used fashion until the count is met.

Parameters:
objectDescription - is the object's unique description.
objectClass - is the object's "class", or grouping for the purposes of LRU.
maxCount - is the maximum number of objects of the class to permit to remain in the cache.

invalidateKeys

public void invalidateKeys(StringSet keys)
Invalidate a set of keys. This causes all objects that have any of the specified keys as invalidation keys to be removed from the cache.

Parameters:
keys - is the StringSet describing the keys to invalidate.

expireRecords

public void expireRecords(long expireTime)
Expire all records that have older expiration times than that passed in.

Parameters:
expireTime - is the time to compare against, in milliseconds since epoch.

deleteEntry

protected void deleteEntry(GeneralCache.ObjectRecord record)
Delete a record from the cache. NOTE WELL: This method cannot be used if the data associated with the record is currently being processed with an enumeration (for example), since it modifies the structures that the enumeration is based on!

Parameters:
record - is the object record.