com.partnersoft.gadgets
Class HashedCache

java.lang.Object
  extended by com.partnersoft.gadgets.HashedCache

public abstract class HashedCache
extends java.lang.Object

A fixed-size caching implementation based on a hashed index.

Author:
Paul Reavis Copyright 1998 Partner Software, Inc.

Field Summary
static int DEFAULTSIZE
           
 
Constructor Summary
HashedCache()
          Create a hashed cache of the default size, 42.
HashedCache(int size)
          Create a hashed cache of the desired size.
 
Method Summary
 void clear()
          Clears all items from the cache, so that they must be reloaded.
 void finalize(java.lang.Object flushCandidate)
          Optional override for subclasses - called before flushing an object.
 java.lang.Object getCached(java.lang.Object index)
           
 int getCacheSize()
           
abstract  java.lang.Object getUncached(java.lang.Object index)
          Subclasses must implement this - it does the "real fetch" of the object, uncached, however appropriate for your use.
 boolean getUsingSeparateReaperThread()
          If true, creates a separate thread which reaps old entries from the cache.
 boolean isFlushable(java.lang.Object flushCandidate)
          Optional override for subclasses - tests if an object can be flushed.
 boolean remove(java.lang.Object index)
           
 void setCacheSize(int newSize)
           
 void setUsingSeparateReaperThread(boolean tizit)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULTSIZE

public static final int DEFAULTSIZE
See Also:
Constant Field Values
Constructor Detail

HashedCache

public HashedCache()
Create a hashed cache of the default size, 42.


HashedCache

public HashedCache(int size)
Create a hashed cache of the desired size.

Method Detail

getCached

public java.lang.Object getCached(java.lang.Object index)

finalize

public void finalize(java.lang.Object flushCandidate)
Optional override for subclasses - called before flushing an object. Does nothing by default.


isFlushable

public boolean isFlushable(java.lang.Object flushCandidate)
Optional override for subclasses - tests if an object can be flushed. Returns true by default.


getUncached

public abstract java.lang.Object getUncached(java.lang.Object index)
Subclasses must implement this - it does the "real fetch" of the object, uncached, however appropriate for your use. getCached() calls this method when it misses.


clear

public void clear()
Clears all items from the cache, so that they must be reloaded.


getCacheSize

public int getCacheSize()

setCacheSize

public void setCacheSize(int newSize)

getUsingSeparateReaperThread

public boolean getUsingSeparateReaperThread()
If true, creates a separate thread which reaps old entries from the cache. If false, reaping is done whenever new items are added.


setUsingSeparateReaperThread

public void setUsingSeparateReaperThread(boolean tizit)

remove

public boolean remove(java.lang.Object index)