net.sf.swarmcache
Class TimerCache

java.lang.Object
  |
  +--net.sf.swarmcache.TimerCache
All Implemented Interfaces:
ObjectCache, java.lang.Runnable

public class TimerCache
extends java.lang.Object
implements ObjectCache, java.lang.Runnable

Cache implementation that times out cached elements. Each item put in the cache is timed out after a specified number of milliseconds (unless removed before the timeout).

Author:
John Watkinson

Field Summary
static java.lang.String CACHE_TIMEOUT_PROPERTY
          The property containing the cache timeout (in milliseconds).
static int DEFAULT_CACHE_TIMEOUT
          The default cache timeout (1 minute).
 
Constructor Summary
TimerCache()
           
 
Method Summary
 java.lang.Object clear(java.io.Serializable key)
          Clears an object from the cache by key.
 void clearAll()
          Clears the entire cache.
 java.lang.Object get(java.io.Serializable key)
          Gets an object from the cache by key, or returns null if that object is not cached.
 java.lang.String getType()
          Gets the cache type name.
 void put(java.io.Serializable key, java.lang.Object object)
          Caches an object.
 void run()
           
 void setTimeout(long newTimeout)
          Sets a new timeout value-- only do this before using the cache!
 void setType(java.lang.String type)
          Sets the cache type name.
 void stop()
          Called to stop the timer thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CACHE_TIMEOUT_PROPERTY

public static final java.lang.String CACHE_TIMEOUT_PROPERTY
The property containing the cache timeout (in milliseconds).

See Also:
Constant Field Values

DEFAULT_CACHE_TIMEOUT

public static final int DEFAULT_CACHE_TIMEOUT
The default cache timeout (1 minute).

See Also:
Constant Field Values
Constructor Detail

TimerCache

public TimerCache()
Method Detail

setTimeout

public void setTimeout(long newTimeout)
Sets a new timeout value-- only do this before using the cache!


stop

public void stop()
Called to stop the timer thread. This should only be called once and the cache should not be used afterwards.


getType

public java.lang.String getType()
Gets the cache type name.

Specified by:
getType in interface ObjectCache

setType

public void setType(java.lang.String type)
Sets the cache type name.

Specified by:
setType in interface ObjectCache

put

public void put(java.io.Serializable key,
                java.lang.Object object)
Caches an object. If object is null, then any object cached at the given key is removed from the cache.

Specified by:
put in interface ObjectCache

get

public java.lang.Object get(java.io.Serializable key)
Description copied from interface: ObjectCache
Gets an object from the cache by key, or returns null if that object is not cached.

Specified by:
get in interface ObjectCache

clear

public java.lang.Object clear(java.io.Serializable key)
Description copied from interface: ObjectCache
Clears an object from the cache by key.

Specified by:
clear in interface ObjectCache

clearAll

public void clearAll()
Description copied from interface: ObjectCache
Clears the entire cache.

Specified by:
clearAll in interface ObjectCache

run

public void run()
Specified by:
run in interface java.lang.Runnable