net.spy.cache
Class SimpleCache

java.lang.Object
  extended by net.spy.SpyObject
      extended by net.spy.cache.SimpleCache

public class SimpleCache
extends SpyObject

A simple time-based cache.


Constructor Summary
protected SimpleCache()
          Get an instance of SimpleCache.
 
Method Summary
 Object get(String key)
          Get an object from the cache.
static SimpleCache getInstance()
          Get the singleton SimpleCache instance.
 Object remove(String key)
          Remove an object from the cache.
 boolean remove(String key, Object value)
          Conditionally remove an object from the cache.
static void setInstance(SimpleCache to)
          Set the singleton SimpleCache instance.
 void store(String key, Object value, long timeout)
          Store an object in the cache.
 
Methods inherited from class net.spy.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleCache

protected SimpleCache()
Get an instance of SimpleCache.

Method Detail

getInstance

public static SimpleCache getInstance()
Get the singleton SimpleCache instance.


setInstance

public static void setInstance(SimpleCache to)
Set the singleton SimpleCache instance. This also cleanly shuts down the previous instance.


get

public Object get(String key)
Get an object from the cache. If the stored object is a reference, it'll be dereferenced before returned.

Parameters:
key - the cache key
Returns:
the cached object

store

public void store(String key,
                  Object value,
                  long timeout)
Store an object in the cache.

Parameters:
key - the cache key
timeout - how long until it's deleted
value - the value to cache

remove

public Object remove(String key)
Remove an object from the cache.

Parameters:
key - the key of the object to remove
Returns:
the previous object under this key (null if there wasn't one)

remove

public boolean remove(String key,
                      Object value)
Conditionally remove an object from the cache. The object will only be removed if the value is equal to the specified value.

Parameters:
key - the key
value - the value
Returns:
true if a value was removed


Copyright © 1995-2007 SPY Internetworking. All Rights Reserved.