org.mmbase.cache
Class Cache

java.lang.Object
  extended byjava.util.Dictionary
      extended byjava.util.Hashtable
          extended byorg.mmbase.util.LRUHashtable
              extended byorg.mmbase.cache.Cache
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable, SizeMeasurable
Direct Known Subclasses:
AbstractImages.CKeyCache, Contexts.OperationsCache, FactoryCache, NodeCache, QueryResultCache, RelationsCache, ResultCache, TemplateCache, URLCache

public abstract class Cache
extends LRUHashtable
implements SizeMeasurable

A base class for all Caches. Extend this class for other caches.

Version:
$Id: Cache.java,v 1.19.2.1 2004/08/04 13:42:19 michiel Exp $
Author:
Michiel Meeuwissen
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class org.mmbase.util.LRUHashtable
LRUHashtable.LRUEntry, LRUHashtable.LRUEntrySet, LRUHashtable.LRUEntrySetIterator
 
Field Summary
protected  int maxEntrySize
           
 
Constructor Summary
Cache(int size)
           
 
Method Summary
 java.lang.Object get(java.lang.Object key)
          Like 'get' of LRUHashtable but considers if the cache is active or not.
 int getByteSize()
          Determins the byte-size of this object
 int getByteSize(SizeOf sizeof)
          Determins the byte-size of this object using the given SizeOf instance.
static Cache getCache(java.lang.String name)
          Returns the Cache with a certain name.
static java.util.Set getCaches()
          Returns the names of all caches.
protected  int getDefaultMaxEntrySize()
          This has to be overridden by Caches which support max entry size.
 java.lang.String getDescription()
          Gives a description for this cache type.
 int getMaxEntrySize()
          Return the maximum entry size for the cache in bytes.
 java.lang.String getName()
          Returns a name for this cache type.
static int getTotalByteSize()
           
 boolean isActive()
          Wether this cache is active or not.
static void main(java.lang.String[] args)
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Like 'put' of LRUHashtable but considers if the cache is active or not.
 Cache putCache()
          Puts this cache in the caches repository.
protected static Cache putCache(Cache cache)
          Puts a cache in the caches repository.
 void setActive(boolean a)
          Sets this cache to active or passive.
 
Methods inherited from class org.mmbase.util.LRUHashtable
clear, clone, elements, entrySet, getCount, getHits, getMisses, getOrderedElements, getOrderedElements, getOrderedEntries, getOrderedEntries, getPuts, getRatio, getSize, getStats, keySet, remove, setSize, size, toString, toString, values
 
Methods inherited from class java.util.Hashtable
contains, containsKey, containsValue, equals, hashCode, isEmpty, keys, putAll, rehash
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

maxEntrySize

protected int maxEntrySize
Constructor Detail

Cache

public Cache(int size)
Method Detail

getName

public java.lang.String getName()
Returns a name for this cache type. Default it is the class name, but this normally will be overriden.


getDescription

public java.lang.String getDescription()
Gives a description for this cache type. This can be used in cache overviews.


getMaxEntrySize

public int getMaxEntrySize()
Return the maximum entry size for the cache in bytes. If the cache-type support it (default no), then no values bigger then this will be stored in the cache.


getDefaultMaxEntrySize

protected int getDefaultMaxEntrySize()
This has to be overridden by Caches which support max entry size.


putCache

protected static Cache putCache(Cache cache)
Puts a cache in the caches repository. This function will be called in the static of childs, therefore it is protected.

Returns:
The previous cache of the same type (stored under the same name)

putCache

public Cache putCache()
Puts this cache in the caches repository.


getCache

public static Cache getCache(java.lang.String name)
Returns the Cache with a certain name. To be used in combination with getCaches(). If you need a certain cache, you can just as well call the non-static 'getCache' which is normally in cache singletons.

See Also:
getCaches()

getCaches

public static java.util.Set getCaches()
Returns the names of all caches.

Returns:
A Set containing the names of all caches.

get

public java.lang.Object get(java.lang.Object key)
Like 'get' of LRUHashtable but considers if the cache is active or not.

Specified by:
get in interface java.util.Map
Overrides:
get in class LRUHashtable
Parameters:
key - the key of the element
Returns:
the value of the element, or null if it could not be found

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Like 'put' of LRUHashtable but considers if the cache is active or not.

Specified by:
put in interface java.util.Map
Overrides:
put in class LRUHashtable
Parameters:
key - the key of the element
value - the value of the element
Returns:
the original value of the element if it existed, null if it could not be found

setActive

public void setActive(boolean a)
Sets this cache to active or passive. TODO: Writing back to caches.xml if necessary (if this call was nog caused by change of caches.xml itself)


isActive

public final boolean isActive()
Wether this cache is active or not.


getByteSize

public int getByteSize()
Description copied from interface: SizeMeasurable
Determins the byte-size of this object

Specified by:
getByteSize in interface SizeMeasurable

getByteSize

public int getByteSize(SizeOf sizeof)
Description copied from interface: SizeMeasurable
Determins the byte-size of this object using the given SizeOf instance. A SizeOf instance stores a Set already counted objects. So this method is typically called by SizeOf itself (recursion).

Specified by:
getByteSize in interface SizeMeasurable

getTotalByteSize

public static int getTotalByteSize()

main

public static void main(java.lang.String[] args)


MMBase build 1.7.1.20041002