org.onemind.commons.java.datastructure
Class LookupCache

java.lang.Object
  extended byorg.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)

Constructor Summary
LookupCache()
          {@inheritDoc}
LookupCache(boolean doNegCache)
          {@inheritDoc}
 
Method Summary
protected  void clearNegCache()
          Clear all the negative cache
protected  boolean isInCache(java.lang.Object o)
          Test if the key is in cache
protected  boolean isInNegCache(java.lang.Object o)
          Get whether the object is in negative cache
protected  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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LookupCache

public LookupCache()
{@inheritDoc}


LookupCache

public LookupCache(boolean doNegCache)
{@inheritDoc}

Parameters:
doNegCache - whether to do negative caching
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



Copyright © 2004-2006 . All Rights Reserved.