org.egothor.cache
Class CachedGroup

java.lang.Object
  extended by org.egothor.cache.CachedGroup

public class CachedGroup
extends java.lang.Object

Represents a cache of optionally paged query results.


Constructor Summary
CachedGroup(Cache<CachedQuery,CachedResult> cache)
          Constructor for the CachedGroup object.
CachedGroup(Cache<CachedQuery,CachedResult> cache, boolean cacheMetadata)
          Constructor for the CachedGroup object.
CachedGroup(Cache<CachedQuery,CachedResult> cache, int pageSize)
          Constructor for the CachedGroup object.
CachedGroup(Cache<CachedQuery,CachedResult> cache, int pageSize, boolean cacheMetadata)
          Constructor for the CachedGroup object.
 
Method Summary
 boolean cachingMetadata()
          Checks whether this cache should cache also document metadata.
 boolean containsKey(CachedQuery key)
          Checks whether the specified query is cached.
 CachedResult get(CachedQuery key)
          Gets the result associated with the specified query from the cache if the query is cached, or the result returned by the resolver.
 Cache<CachedQuery,CachedResult> getCache()
          Gets the actual cache used for storing query results.
 float hitRatio()
          Returns the hits/requests ratio in percents.
 long hits()
          Returns the number of all hits.
 boolean isPaged()
          Checks whether this cache uses paged query results.
 long misses()
          Returns the number of all misses.
 int pageSize()
          Return the capacity of query result page.
 CachedResult put(CachedQuery key, CachedResult value)
          Adds a new result for the specified query to the cache.
 CachedResult remove(CachedQuery key)
          Removes the specified query and its result from the cache.
 long requests()
          Returns the number of all submitted requests
 void resetCounters()
          Sets hits and misses counters to zero.
 int size()
          Returns the number of cached query result.
 CachedResult update(CachedQuery key, CachedResult value)
          Updates the result associated with the specified query in the cache if a result exists for the query.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedGroup

public CachedGroup(Cache<CachedQuery,CachedResult> cache)
Constructor for the CachedGroup object. Does not use paging and caches document metadata.

Parameters:
cache - actual cache used for storing query results

CachedGroup

public CachedGroup(Cache<CachedQuery,CachedResult> cache,
                   int pageSize)
Constructor for the CachedGroup object. Caches document metadata.

Parameters:
cache - actual cache used for storing query results
pageSize - maximum size of a page

CachedGroup

public CachedGroup(Cache<CachedQuery,CachedResult> cache,
                   boolean cacheMetadata)
Constructor for the CachedGroup object. Does not use paging.

Parameters:
cache - actual cache used for storing query results
cacheMetadata - whether we want do cache also documents with metadata

CachedGroup

public CachedGroup(Cache<CachedQuery,CachedResult> cache,
                   int pageSize,
                   boolean cacheMetadata)
Constructor for the CachedGroup object.

Parameters:
cache - actual cache used for storing query results
pageSize - maximum size of a page
cacheMetadata - whether we want do cache also documents with metadata
Method Detail

put

public CachedResult put(CachedQuery key,
                        CachedResult value)
Adds a new result for the specified query to the cache. If the query was previously cached, it is removed at first. If the cache is full, a result is removed from the cache according to the current eviction policy.

Parameters:
key - query to add to the cache
value - result to map the query to
Returns:
previous result associated with the query or null if the query was not previously cached

get

public CachedResult get(CachedQuery key)
Gets the result associated with the specified query from the cache if the query is cached, or the result returned by the resolver.

Parameters:
key - query to get the result for
Returns:
result associated with the query from the cache, or from the resolver if the query was not cached

remove

public CachedResult remove(CachedQuery key)
Removes the specified query and its result from the cache.

Parameters:
key - query to remove from the cache.
Returns:
result associated with the query, or null if the query was not cached

update

public CachedResult update(CachedQuery key,
                           CachedResult value)
Updates the result associated with the specified query in the cache if a result exists for the query.

Parameters:
key - query to change the result for
value - new result associated with the key
Returns:
previous associated result or null if the query is not cached

containsKey

public boolean containsKey(CachedQuery key)
Checks whether the specified query is cached.

Parameters:
key - query to check
Returns:
true, if the query is currently cached, false otherwise

isPaged

public boolean isPaged()
Checks whether this cache uses paged query results.

Returns:
true, if query results are paged, false otherwise

cachingMetadata

public boolean cachingMetadata()
Checks whether this cache should cache also document metadata.

Returns:
true, if we are caching document metadata, false otherwise

pageSize

public int pageSize()
Return the capacity of query result page. If is equal or smaller than zero than no paging is used.

Returns:
capacity of query result page

getCache

public Cache<CachedQuery,CachedResult> getCache()
Gets the actual cache used for storing query results.

Returns:
actual cache used for storing query results

hits

public long hits()
Returns the number of all hits.

Returns:
number of all hits

misses

public long misses()
Returns the number of all misses.

Returns:
number of all misses

requests

public long requests()
Returns the number of all submitted requests

Returns:
number of all submitted requests

hitRatio

public float hitRatio()
Returns the hits/requests ratio in percents.

Returns:
hit ratio of the cache

resetCounters

public void resetCounters()
Sets hits and misses counters to zero.


size

public int size()
Returns the number of cached query result.

Returns:
number cached query result