org.progeeks.util
Class Cache

java.lang.Object
  extended by org.progeeks.util.Cache
Direct Known Subclasses:
MetaObjectCache

public class Cache
extends java.lang.Object

A simple cache structure that uses Reference objects to hold objects and a background thread to reap dead entries when they go away. Subclasses can define different cache miss behavior or the class can just be used directly as a simple weak-referenced cache (ie: if the object is GC'ed it will be removed from cache.)

Version:
$Revision: 1.4 $
Author:
Paul Speed

Constructor Summary
Cache()
           
 
Method Summary
 void cacheObject(java.lang.Object id, java.lang.Object obj)
          Caches the specified object associated with the specified key.
 java.lang.Object getCachedObject(java.lang.Object id)
          Returns the cached object for the specified ID if it exists or null if it is not in the cache.
 boolean uncacheObject(java.lang.Object id)
          Uncaches the object for the specified ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cache

public Cache()
Method Detail

getCachedObject

public java.lang.Object getCachedObject(java.lang.Object id)
Returns the cached object for the specified ID if it exists or null if it is not in the cache.


cacheObject

public void cacheObject(java.lang.Object id,
                        java.lang.Object obj)
Caches the specified object associated with the specified key.


uncacheObject

public boolean uncacheObject(java.lang.Object id)
Uncaches the object for the specified ID. Returns true if the object existed in the cache prior to this call.



Copyright © 2002-2003 Paul Speed. All Rights Reserved.