ewe.util
Class WeakCache

java.lang.Object
  extended byewe.util.WeakCache

public class WeakCache
extends Object

This is similar to a Hashtable in that you associate values with keys. However only weak references are kept to the keys - which means that the key values can be garbage collected, in which case it will not be possible to access the object values the keys refer to.

The clean() method explicitly removes entries where the keys have been garbage collected.

A background thread is created to clean all existing WeakCache objects at regular intervals. The default interval is 1 minute, but this can be changed by calling setCleanInterval().


Constructor Summary
WeakCache()
           
 
Method Summary
 void clean()
          Remove all entries for which the key has been garbage collected.
 Object get(Object key)
           
 Iterator keys()
          Each object returned by the returned Iterator will be a WeakReference.
 void put(Object key, Object data)
           
static void setCleanInterval(long interval)
          Set the interval between cache cleaning in milliseconds.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Constructor Detail

WeakCache

public WeakCache()
Method Detail

setCleanInterval

public static void setCleanInterval(long interval)
Set the interval between cache cleaning in milliseconds.

Parameters:
interval - the interval in milliseconds. If this is less 1 then the default value of 60000 (1 minute) will be used.

clean

public void clean()
Remove all entries for which the key has been garbage collected.


put

public void put(Object key,
                Object data)

get

public Object get(Object key)

keys

public Iterator keys()
Each object returned by the returned Iterator will be a WeakReference.

Returns:
an Iterator that iterates through the WeakReferences.