org.cdlib.xtf.cache
Class SimpleCache<K,V>

Object
  extended by Cache<K,V>
      extended by SimpleCache<K,V>
Direct Known Subclasses:
StringCache

public class SimpleCache<K,V>
extends Cache<K,V>

A cache that holds key/value pairs. The value is specifed when a key is added to the cache.


Nested Class Summary
 
Nested classes/interfaces inherited from class Cache
Cache.ListEntry, Cache.NullIterator
 
Field Summary
 
Fields inherited from class Cache
ageList, keyMap
 
Constructor Summary
SimpleCache(int maxEntries, int maxTime)
          Constructor - sets up the parameters of the cache.
 
Method Summary
 void addDependency(K key, Dependency d)
          Add a dependency to an existing entry.
 V get(K key)
          Gets the value associated with a key, or null if none.
 void set(K key, V value)
          Set the value for a key.
 void set(K key, V value, Dependency dependency)
          Set the value for a key, optionally adding a dependency for it.
 
Methods inherited from class Cache
cleanup, clear, dependenciesValid, getDependencies, has, lastSet, logAction, remove, size
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleCache

public SimpleCache(int maxEntries,
                   int maxTime)
Constructor - sets up the parameters of the cache.

Parameters:
maxEntries - Maximum # of entries. Beyond this, older ones will be removed. Zero means no limit.
maxTime - Time (in seconds) an entry can stay in the cache without being used. Entries older than this will be removed. Zero means no limit.
Method Detail

set

public void set(K key,
                V value)
Set the value for a key. If already present, the old value is replaced.

Parameters:
key - Key to set the value for
value - Value for that key.

set

public void set(K key,
                V value,
                Dependency dependency)
Set the value for a key, optionally adding a dependency for it. If the key is already present, the old value is replaced.

Parameters:
key - The key that will be used to look up the value
value - The value to associate with that key
dependency - A dependency to add to the key, or null for none.

get

public V get(K key)
Gets the value associated with a key, or null if none.

Parameters:
key - The key to look for
Returns:
The value for that key, or null if the key isn't in the cache.

addDependency

public void addDependency(K key,
                          Dependency d)
Add a dependency to an existing entry. If the dependency later becomes invalid, the key will be removed from the cache.

Parameters:
key - The key to add a dependency to
d - The dependency to add to it.