org.cdlib.xtf.cache
Class SimpleCache<K,V>
Object
Cache<K,V>
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.
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 Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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.
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 forvalue
- 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 valuevalue
- The value to associate with that keydependency
- 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 tod
- The dependency to add to it.