com.opencms.template.cache
Class CmsLruCache

java.lang.Object
  |
  +--com.opencms.template.cache.CmsLruCache

public class CmsLruCache
extends Object

This class implements a LRU cache. It uses a Hashtable algorithm with the chaining method for collision handling. The sequence of the Objects is stored in an extra chain. Each object has a pointer to the previous and next object in this chain. If an object is inserted or used it is set to the tail of the chain. If an object has to be remouved it will be the head object. Only works with more than one element.

Version:
1.0
Author:
Hanjo Riege

Constructor Summary
CmsLruCache(int size)
          Constructor
 
Method Summary
 void clearCache()
          Clears the cache completly.
 Vector deleteElementsAfterPublish()
          Deletes elements after publish.
 Vector deleteElementsByClass(String className)
          Deletes all elements that depend on the class.
 Vector deleteElementsByTemplate(String templateName)
          Deletes all elements that depend on the template.
 void deleteUri(String uri)
          Deletes the uri from the Cache.
 Object get(Object key)
          returns the value to the key or null if the key is not in the cache.
 Vector getAllKeys()
          gets all keys in the cache.
 Vector getCacheInfo()
          Gets the Information of max size and size for the cache.
 Vector put(Object key, Object value)
          inserts a new object in the cache.
 void remove(Object key)
          removes on item from the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsLruCache

public CmsLruCache(int size)
Constructor

Parameters:
size - The size of the cache.
Method Detail

put

public Vector put(Object key,
                  Object value)
inserts a new object in the cache. If it is there already the value is updated.

Parameters:
key - The key to find the object.
value - The object.
Returns:
if the cache is full the deleted object, null otherwise.

get

public Object get(Object key)
returns the value to the key or null if the key is not in the cache. The found element has to line up behind the others (set to the tail).

Parameters:
key - The key for the object.
Returns:
The value.

remove

public void remove(Object key)
removes on item from the cache.

Parameters:
key - .The key to find the item.

deleteElementsByTemplate

public Vector deleteElementsByTemplate(String templateName)
Deletes all elements that depend on the template. use only if the cache is for elements.

Returns:
Vector a Vector with deleted items. Each item is a Vector with two elements: key and value.

deleteElementsByClass

public Vector deleteElementsByClass(String className)
Deletes all elements that depend on the class. use only if this cache is for elements.

Returns:
Vector a Vector with deleted items. Each item is a Vector with two elements: key and value.

deleteElementsAfterPublish

public Vector deleteElementsAfterPublish()
Deletes elements after publish. All elements that depend on the uri and all element that say so have to be removed. use only if this cache is for elements.

Returns:
Vector a Vector with deleted items. Each item is a Vector with two elements: key and value.

deleteUri

public void deleteUri(String uri)
Deletes the uri from the Cache. Use only if this is the cache for uris.


clearCache

public void clearCache()
Clears the cache completly.


getCacheInfo

public Vector getCacheInfo()
Gets the Information of max size and size for the cache.

Returns:
a Vector whith informations about the size of the cache.

getAllKeys

public Vector getAllKeys()
gets all keys in the cache.

Returns:
a vector with the keys.