|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.groboutils.util.datastruct.v1.HashCache
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.
Nested Class Summary | |
static interface |
HashCache.ObjectManager
An interface which needs to be implemented and given to the cache in order to create new instances. |
Constructor Summary | |
HashCache(HashCache.ObjectManager om,
int maxSize)
Create a new HashCache. |
Method Summary | |
void |
clear()
Cleans out the data structure, calling the clean-up on all items. |
java.lang.Object |
get(java.lang.Object key)
Retrieves an item from the cache with the given key. |
int |
getMaxSize()
Retrieves the maximum cache size. |
int |
getOverflowCount()
Retrieves the metric that corresponds to the number of objects that were removed from the cache. |
int |
getSize()
Retrieves the current number of elements in the cache. |
void |
resetOverflowCount()
Resets the overflow count metric. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public HashCache(HashCache.ObjectManager om, int maxSize)
om
- the manager for creating and cleaning up the objects. This
cannot be null.maxSize
- the maximum size of the cache. This must be > 1
(this is for performance reasons).Method Detail |
public java.lang.Object get(java.lang.Object key)
public int getSize()
public int getMaxSize()
public int getOverflowCount()
public void resetOverflowCount()
public void clear()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |