Jive Forums API (5.5.20.2-oracle) Developer Javadocs

com.jivesoftware.forum.database
Class QueryCache

java.lang.Object
  extended by com.jivesoftware.forum.database.QueryCache
All Implemented Interfaces:
Cache, java.util.Map

public class QueryCache
extends java.lang.Object
implements Cache

Cache for storing query results. Cache contents are essentially hierarchical in nature since every cache entry is associated with a particular object (identified by object type and id). We track this information so that mass removes can be made for all entries associated with a particular object.


Nested Class Summary
static interface QueryCache.PutGetRemoveStrategy
          Defines a strategy object for different mechanisms to do the actual map access.
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
static int BLOCK_SIZE
          Number of forumID's per cache block.
 
Constructor Summary
QueryCache(ClusteredCache cache)
          Create a new QueryCache with specified cache as the backing cache.
QueryCache(CoherenceCache cache)
          Create a new QueryCache with specified cache as the backing cache.
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set entrySet()
          This method throws UnsupportedOperationException.
 java.lang.Object get(java.lang.Object key)
           
protected static long[] getBlock(CachedPreparedStatement cachedPstmt, int objectType, long objectID, int startIndex, boolean useCache)
          Returns a block of objectID's (threads or messages) from a query and performs transparent caching of those blocks.
static java.util.List getBlock(QueryCacheStrategy queryStrategy, CachedPreparedStatement cachedPstmt, int objectType, long objectID, int startIndex, boolean useCache)
          Returns a List of objects from a query and performs transparent caching of those blocks.
 long getCacheHits()
          Returns the number of cache hits.
 long getCacheMisses()
          Returns the number of cache misses.
 int getCacheSize()
          Returns the size of the cache contents in bytes.
protected static int getCount(QueryCacheKey key, boolean useCache)
          Returns the count associated with a ResultFilter query.
 int getMaxCacheSize()
          Returns the maximum size of the cache in bytes.
 long getMaxLifetime()
          Returns the maximum number of milliseconds that any object can live in cache.
 java.lang.String getName()
          Returns the name of the cache.
 boolean isEmpty()
           
 java.util.Set keySet()
          This method throws UnsupportedOperationException.
 void moveToShortTerm(java.util.Collection keys)
          Iterates a set of keys, moving each entry to the short term query cache.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void putAll(java.util.Map map)
          This method throws UnsupportedOperationException.
 void remove(int objectType, long objectID)
          Removes all query keys that match the objectType and objectID combination.
 java.lang.Object remove(java.lang.Object key)
           
 void removeUsers()
          Removes all entries associated with users.
 void setMaxCacheSize(int maxSize)
          Sets the maximum size of the cache in bytes.
 void setMaxLifetime(long maxLifetime)
          Sets the maximum number of milliseconds that any object can live in cache.
 void setName(java.lang.String name)
          Sets the name of the cache
 int size()
           
 java.util.Collection values()
          This method throws UnsupportedOperationException.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

BLOCK_SIZE

public static final int BLOCK_SIZE
Number of forumID's per cache block.

See Also:
Constant Field Values
Constructor Detail

QueryCache

public QueryCache(CoherenceCache cache)
Create a new QueryCache with specified cache as the backing cache.

Parameters:
cache - the backing cache.

QueryCache

public QueryCache(ClusteredCache cache)
Create a new QueryCache with specified cache as the backing cache.

Parameters:
cache - the backing cache.
Method Detail

getBlock

protected static long[] getBlock(CachedPreparedStatement cachedPstmt,
                                 int objectType,
                                 long objectID,
                                 int startIndex,
                                 boolean useCache)
Returns a block of objectID's (threads or messages) from a query and performs transparent caching of those blocks. The two parameters specify a database query and a startIndex for the results in that query.

Parameters:
cachedPstmt - the SQL query.
startIndex - the startIndex in the list to get a block for.

getBlock

public static java.util.List getBlock(QueryCacheStrategy queryStrategy,
                                      CachedPreparedStatement cachedPstmt,
                                      int objectType,
                                      long objectID,
                                      int startIndex,
                                      boolean useCache)
Returns a List of objects from a query and performs transparent caching of those blocks.

Parameters:
queryStrategy - the query strategy to use to retrieve the object
cachedPstmt - the SQL query.
objectType - the type of the container object
objectID - the id of the container object
startIndex - the startIndex in the list to get a block for.
useCache - true to cache, false to not cache
Returns:
a List of objects

getCount

protected static int getCount(QueryCacheKey key,
                              boolean useCache)
Returns the count associated with a ResultFilter query.

Parameters:
key - the key associted with the query.

remove

public void remove(int objectType,
                   long objectID)
Removes all query keys that match the objectType and objectID combination. For example, we could remove all query keys associated with a forum at once.

Parameters:
objectType - the object type.
objectID - the id of the object.

removeUsers

public void removeUsers()
Removes all entries associated with users.


moveToShortTerm

public void moveToShortTerm(java.util.Collection keys)
Iterates a set of keys, moving each entry to the short term query cache.

Parameters:
keys - the keys to move.

getName

public java.lang.String getName()
Description copied from interface: Cache
Returns the name of the cache.

Specified by:
getName in interface Cache
Returns:
the name of the cache.

setName

public void setName(java.lang.String name)
Description copied from interface: Cache
Sets the name of the cache

Specified by:
setName in interface Cache
Parameters:
name - the name of the cache

getMaxCacheSize

public int getMaxCacheSize()
Description copied from interface: Cache
Returns the maximum size of the cache in bytes. If the cache grows larger than the max size, the least frequently used items will be removed. If the max cache size is set to -1, there is no size limit.

Specified by:
getMaxCacheSize in interface Cache
Returns:
the maximum size of the cache in bytes.

setMaxCacheSize

public void setMaxCacheSize(int maxSize)
Description copied from interface: Cache
Sets the maximum size of the cache in bytes. If the cache grows larger than the max size, the least frequently used items will be removed. If the max cache size is set to -1, there is no size limit.

Specified by:
setMaxCacheSize in interface Cache
Parameters:
maxSize - the maximum size of the cache in bytes.

getMaxLifetime

public long getMaxLifetime()
Description copied from interface: Cache
Returns the maximum number of milliseconds that any object can live in cache. Once the specified number of milliseconds passes, the object will be automatically expried from cache. If the max lifetime is set to -1, then objects never expire.

Specified by:
getMaxLifetime in interface Cache
Returns:
the maximum number of milliseconds before objects are expired.

setMaxLifetime

public void setMaxLifetime(long maxLifetime)
Description copied from interface: Cache
Sets the maximum number of milliseconds that any object can live in cache. Once the specified number of milliseconds passes, the object will be automatically expried from cache. If the max lifetime is set to -1, then objects never expire.

Specified by:
setMaxLifetime in interface Cache
Parameters:
maxLifetime - the maximum number of milliseconds before objects are expired.

getCacheSize

public int getCacheSize()
Description copied from interface: Cache
Returns the size of the cache contents in bytes. This value is only a rough approximation, so cache users should expect that actual VM memory used by the cache could be significantly higher than the value reported by this method.

Specified by:
getCacheSize in interface Cache
Returns:
the size of the cache contents in bytes.

getCacheHits

public long getCacheHits()
Description copied from interface: Cache
Returns the number of cache hits. A cache hit occurs every time the get method is called and the cache contains the requested object.

Keeping track of cache hits and misses lets one measure how efficient the cache is; the higher the percentage of hits, the more efficient.

Specified by:
getCacheHits in interface Cache
Returns:
the number of cache hits.

getCacheMisses

public long getCacheMisses()
Description copied from interface: Cache
Returns the number of cache misses. A cache miss occurs every time the get method is called and the cache does not contain the requested object.

Keeping track of cache hits and misses lets one measure how efficient the cache is; the higher the percentage of hits, the more efficient.

Specified by:
getCacheMisses in interface Cache
Returns:
the number of cache hits.

size

public int size()
Specified by:
size in interface java.util.Map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map

remove

public java.lang.Object remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map

clear

public void clear()
Specified by:
clear in interface java.util.Map

putAll

public void putAll(java.util.Map map)
This method throws UnsupportedOperationException.

Specified by:
putAll in interface java.util.Map
Throws:
java.lang.UnsupportedOperationException

keySet

public java.util.Set keySet()
This method throws UnsupportedOperationException.

Specified by:
keySet in interface java.util.Map
Throws:
java.lang.UnsupportedOperationException

values

public java.util.Collection values()
This method throws UnsupportedOperationException.

Specified by:
values in interface java.util.Map
Throws:
java.lang.UnsupportedOperationException

entrySet

public java.util.Set entrySet()
This method throws UnsupportedOperationException.

Specified by:
entrySet in interface java.util.Map
Throws:
java.lang.UnsupportedOperationException

Jive Forums Project Page

Copyright © 1999-2006 Jive Software.