jrunx.util
Class Cache

java.lang.Object
  |
  +--jrunx.util.Cache

public abstract class Cache
extends java.lang.Object

Utility class for caching. The caller must override miss() to provide the logic to fetch a key that is not already in the cache.

This class is designed to be convenient to extend using inner classes, where the implementation of miss() accesses the state of the object or method that is using it.

Keys must not be nulls, but values can be null. Existing keys can be removed at any time. A given implemenation may use soft or weak references, so keys may dissapear even when the system is idle.

This cache is threadsafe, all the time. Uncontested locks in java are essentially free.

Author:
Edwin Smith

Constructor Summary
Cache()
           
Cache(int size)
           
 
Method Summary
 void clear()
           
protected  void expel(java.lang.Object key, java.lang.Object value)
          this expel method is never called.
protected abstract  java.lang.Object fetch(java.lang.Object key)
          subclasses override activate to fetch values that are not in cache.
 java.lang.Object get(java.lang.Object key)
          retreive a value from the cache, invoking activate() if the value is not there.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cache

public Cache()

Cache

public Cache(int size)
Method Detail

fetch

protected abstract java.lang.Object fetch(java.lang.Object key)
subclasses override activate to fetch values that are not in cache.
Returns:
the value to cache. null's are okay.

expel

protected final void expel(java.lang.Object key,
                           java.lang.Object value)
this expel method is never called. We define it here to prevent subclasses from overriding it and thinking that expel is called.

get

public final java.lang.Object get(java.lang.Object key)
retreive a value from the cache, invoking activate() if the value is not there. this method is final -- implementations should override activate(). Note: null values can be stored in the cache. This is useful for resource caches that fail-fast, when a resource doesn't exist. activate() will return null, and null will be stored in the cache under the given key, like any other value.

clear

public void clear()


Copyright � 2002 Macromedia Corporation. All Rights Reserved.