org.mmbase.cache
Class QueryResultCache

java.lang.Object
  extended byjava.util.Dictionary
      extended byjava.util.Hashtable
          extended byorg.mmbase.util.LRUHashtable
              extended byorg.mmbase.cache.Cache
                  extended byorg.mmbase.cache.QueryResultCache
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable, SizeMeasurable
Direct Known Subclasses:
AggregatedResultCache, MultilevelCache, NodeListCache, RelatedNodesCache

public abstract class QueryResultCache
extends Cache

This cache provides a base implementation to cache the result of SearchQuery's. Such a cache links a SearchQuery object to a list of MMObjectNodes. A cache entry is automaticly invalidated if arbitrary node of one of the types present in the SearchQuery is changed (,created or deleted). This mechanism is not very subtle but it is garanteed to be correct. It means though that your cache can be considerably less effective for queries containing node types from which often node are edited.

Since:
MMBase-1.7
Version:
$Id: QueryResultCache.java,v 1.5.2.1 2004/08/26 12:03:10 michiel Exp $
Author:
Daniel Ockeloen, Michiel Meeuwissen
See Also:
SearchQuery, Serialized Form

Nested Class Summary
 
Nested classes inherited from class org.mmbase.util.LRUHashtable
LRUHashtable.LRUEntry, LRUHashtable.LRUEntrySet, LRUHashtable.LRUEntrySetIterator
 
Field Summary
 
Fields inherited from class org.mmbase.cache.Cache
maxEntrySize
 
Method Summary
static int invalidateAll(MMObjectBuilder builder)
          Explicitely invalidates all Query caches for a certain builder.
 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.
 java.lang.Object put(SearchQuery query, java.util.List queryResult)
          Puts a search result in this cache.
 java.lang.Object remove(java.lang.Object key)
          Removes an object from the cache.
 java.lang.String toString()
          Returns a description of the table.
 
Methods inherited from class org.mmbase.cache.Cache
get, getByteSize, getByteSize, getCache, getCaches, getDefaultMaxEntrySize, getDescription, getMaxEntrySize, getName, getTotalByteSize, isActive, main, putCache, putCache, setActive
 
Methods inherited from class org.mmbase.util.LRUHashtable
clear, clone, elements, entrySet, getCount, getHits, getMisses, getOrderedElements, getOrderedElements, getOrderedEntries, getOrderedEntries, getPuts, getRatio, getSize, getStats, keySet, setSize, size, 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
 

Method Detail

invalidateAll

public static int invalidateAll(MMObjectBuilder builder)
Explicitely invalidates all Query caches for a certain builder. This is used in MMObjectBuilder for 'local' changes, to ensure that imediate select after update always works.

Returns:
number of entries invalidated

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Description copied from class: Cache
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 Cache
Throws:
java.lang.ClassCastException - if key not a SearchQuery or value not a List.

put

public java.lang.Object put(SearchQuery query,
                            java.util.List queryResult)
Puts a search result in this cache.


remove

public java.lang.Object remove(java.lang.Object key)
Removes an object from the cache. It alsos remove the watch from the observers which are watching this entry.

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

toString

public java.lang.String toString()
Description copied from class: LRUHashtable
Returns a description of the table. The information shown includes current size, maximum size, ratio of misses and hits, and a description of the underlying hashtable

Overrides:
toString in class LRUHashtable


MMBase build 1.7.1.20041002