iiitToolkit 1.0

de.iiit.cache
Class GenericTimeoutCache

java.lang.Object
  |
  +--de.iiit.cache.GenericCache
        |
        +--de.iiit.cache.GenericTimeoutCache

public class GenericTimeoutCache
extends GenericCache

A cache with background clean-up thread which removes all entries not used for a given period of time.

Version:
$Revision: 1.12 $ $Date: 2003/04/14 20:38:02 $

Constructor Summary
GenericTimeoutCache()
          Creates a new instance of GenericTimeoutCache
GenericTimeoutCache(long timeout)
          Creates a new instance of GenericTimeoutCache
GenericTimeoutCache(long timeout, long sleeptime)
          Creates a new instance of GenericTimeoutCache
 
Method Summary
 void addElement(Object key, Object value)
          Add a new element to the cache.
 Object getElement(Object key)
          Retrieves an cache-entry.
protected  long getElementTimeout(Object key)
          Retrieves the timeout of the cache element.
 void shutdown()
          Stop the cleaner thread
 
Methods inherited from class de.iiit.cache.GenericCache
clear, getKeys, removeElement, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericTimeoutCache

public GenericTimeoutCache()
Creates a new instance of GenericTimeoutCache


GenericTimeoutCache

public GenericTimeoutCache(long timeout)
Creates a new instance of GenericTimeoutCache

Parameters:
timeout - The period of time after which unused entries shall be removed automatically

GenericTimeoutCache

public GenericTimeoutCache(long timeout,
                           long sleeptime)
Creates a new instance of GenericTimeoutCache

Parameters:
timeout - The period of time after which unused entries shall be removed automatically
sleeptime - The amount of time the clean-up thread shall sleep between to runs.
Method Detail

shutdown

public void shutdown()
Stop the cleaner thread


addElement

public void addElement(Object key,
                       Object value)
Add a new element to the cache. If an element with the same key already exists it will be replaced.

Overrides:
addElement in class GenericCache
Parameters:
key - The unique key of the cache entry
value - The value of the cache entry

getElement

public Object getElement(Object key)
                  throws CacheFaultException
Retrieves an cache-entry. The timeout of the cache element is reset by this method.

Overrides:
getElement in class GenericCache
Parameters:
key - The unique key of the cache entry to retrieve
Returns:
The cache entry with the given key
Throws:
CacheFaultException - if there is no entry with the given key

getElementTimeout

protected long getElementTimeout(Object key)
Retrieves the timeout of the cache element. The timeout of the cache element will not be changed by this method.

Parameters:
key - The unique key of the cache entry to retrieve
Returns:
The timeout of the cache element or -1L if there is no element with the given key.

iiitToolkit 1.0

Copyright © 2002, 2003 ingeneurbuero fuer innovative informationstechnik, Dipl.-Ing. Joerg Beckmann, Dortmund, Germany. All Rights Reserved.
See Copyright statement