Class LookupCache
- java.lang.Object
-
- org.onemind.commons.java.datastructure.LookupCache
-
- Direct Known Subclasses:
ClassLookupCache
public abstract class LookupCache extends java.lang.Object
A lookup cache implements simple lookup caching algorithm for looking up things. The derived class simply implement the produce(Object key) method which is assumed an expensive operation and the results will be cached by the lookup cache implementation. There's no public method on lookup cache, the developer should provide application specific lookup interface.- Version:
- $Id: LookupCache.java,v 1.4 2004/09/30 13:26:26 thlee Exp $ $Name: $
- Author:
- TiongHiang Lee (thlee@onemindsoft.org)
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map
_cache
the hit cache *private boolean
_doNegCache
indicate whether to do negative caching *private static java.util.logging.Logger
_logger
the logger *private java.util.Set
_negCache
the negative cache *
-
Constructor Summary
Constructors Constructor Description LookupCache()
LookupCache(boolean doNegCache)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
clearNegCache()
Clear all the negative cacheprotected boolean
isInCache(java.lang.Object o)
Test if the key is in cacheprotected boolean
isInNegCache(java.lang.Object o)
Get whether the object is in negative cacheprotected java.lang.Object
lookup(java.lang.Object key)
The main lookup method.protected abstract java.lang.Object
produce(java.lang.Object key)
Produce the object given the key.protected void
setDoNegativeCache(boolean b)
Turn on/off the negative cache
-
-
-
Method Detail
-
lookup
protected final java.lang.Object lookup(java.lang.Object key)
The main lookup method. The developer should provide another application specific method that call this method to return what the application wants- Parameters:
key
- the key- Returns:
- the object or null
-
produce
protected abstract java.lang.Object produce(java.lang.Object key)
Produce the object given the key. This is assumed to be an expensive operation and it will be called by the lookup method. The result will be cached by the lookup method and negative result also will be cached to if the doNegCache is turned on.- Parameters:
key
- the key- Returns:
- the result or null if no result
-
setDoNegativeCache
protected void setDoNegativeCache(boolean b)
Turn on/off the negative cache- Parameters:
b
- true to turn on the neg cache
-
isInNegCache
protected boolean isInNegCache(java.lang.Object o)
Get whether the object is in negative cache- Parameters:
o
- the object- Returns:
- true if is in negative cache
-
isInCache
protected boolean isInCache(java.lang.Object o)
Test if the key is in cache- Parameters:
o
- the object- Returns:
- true if is in cache
-
clearNegCache
protected void clearNegCache()
Clear all the negative cache
-
-