| java.lang.Object net.sourceforge.groboutils.util.datastruct.v1.HashCache
All known Subclasses: net.sourceforge.groboutils.codecoverage.v2.logger.CacheDirChannelLogger,
HashCache | public class HashCache (Code) | | Stores objects that are created via a unique key in a limited-sized
cache. The objects are retrieved and created through the key. If the
object with a requested key exists in the cache, then it is returned
and the object is marked as the latest accessed object. If a request
is made for an object whose key is not in the cache, then the object
is created, put into the cache, and returned. If the cache is full
when a new object is created, then the oldest item in the cache is
removed.
This class is NOT thread safe. All thread safety issues will need to
be covered by the calling class.
Future versions should use the ObjectCache to cache the node instances.
author: Matt Albrecht groboclown@users.sourceforge.net since: May 23, 2003 version: $Date: 2003/05/23 22:37:57 $ |
Inner Class :public static interface ObjectManager | |
Constructor Summary | |
public | HashCache(ObjectManager om, int maxSize) Create a new HashCache.
Parameters: om - the manager for creating and cleaning up the objects. |
Method Summary | |
public void | clear() Cleans out the data structure, calling the clean-up on all items. | public Object | get(Object key) Retrieves an item from the cache with the given key. | public int | getMaxSize() Retrieves the maximum cache size. | public int | getOverflowCount() Retrieves the metric that corresponds to the number of objects
that were removed from the cache. | public int | getSize() Retrieves the current number of elements in the cache. | public void | resetOverflowCount() Resets the overflow count metric. |
HashCache | public HashCache(ObjectManager om, int maxSize)(Code) | | Create a new HashCache.
Parameters: om - the manager for creating and cleaning up the objects. Thiscannot be null. Parameters: maxSize - the maximum size of the cache. This must be > 1(this is for performance reasons). |
clear | public void clear()(Code) | | Cleans out the data structure, calling the clean-up on all items.
The manager and max size will not be changed, nor will the overflow
count.
|
get | public Object get(Object key)(Code) | | Retrieves an item from the cache with the given key. If the
object doesn't exist, then it is created, added to the cache,
and returned. If it does exist, the cached version is returned
and marked as the most recently found. If it was created,
and the cache is full, then the oldest retrieved object is
removed and cleaned up.
|
getMaxSize | public int getMaxSize()(Code) | | Retrieves the maximum cache size.
the maximum cache size. |
getOverflowCount | public int getOverflowCount()(Code) | | Retrieves the metric that corresponds to the number of objects
that were removed from the cache.
the overflow count. |
getSize | public int getSize()(Code) | | Retrieves the current number of elements in the cache.
the current size of the cache. |
resetOverflowCount | public void resetOverflowCount()(Code) | | Resets the overflow count metric.
|
|
|