org.egothor.cache
Class CachedRider

java.lang.Object
  extended by org.egothor.cache.CachedRider
All Implemented Interfaces:
Resolver<CachedTerm,CachedIListPage>

public class CachedRider
extends java.lang.Object
implements Resolver<CachedTerm,CachedIListPage>

Represents a cache that stores pages of inverted lists for different barrels and terms.


Field Summary
static int DEFAULT_PAGE_SIZE
          Default maximum number of items an inverted list page should store.
 
Constructor Summary
CachedRider(Cache<CachedTerm,CachedIListPage> cache)
          Constructor for the CachedRider object.
CachedRider(Cache<CachedTerm,CachedIListPage> cache, int pageSize)
          Constructor for the CachedRider object.
 
Method Summary
 boolean containsKey(CachedTerm term)
          Checks whether the specified term is cached.
 CachedIListPage get(CachedTerm term)
          Gets the inverted list page associated with the specified term from the cache if the term is cached, or the inverted list page returned by the resolver.
 Cache<CachedTerm,CachedIListPage> getCache()
          Gets the actual cache used for storing inverted list pages.
 long getCachedPostings()
          Returns the actual number of cached postings.
 long getPostings()
          Returns the number of postings that the cached pages occupy.
 float hitRatio()
          Returns the hits/requests ratio in percents.
 long hits()
          Returns the number of all hits.
 long misses()
          Returns the number of all misses.
 IListReader openIList(Barrel barrel, java.lang.String term)
          Gets a cached inverted list reader for the specified barrel and term.
 CachedIListPage put(CachedTerm term, CachedIListPage page)
          Adds a new inverted list page for the specified term to the cache.
 CachedIListPage remove(CachedTerm term)
          Removes the specified term and its page from the cache.
 long requests()
          Returns the number of all submitted requests.
 void resetCounters()
          Sets hits and misses counters to zero.
 CachedIListPage resolve(CachedTerm term)
          Return a new cached inverted list page of the specified term.
 int size()
          Returns the number of cached inverted list pages.
 CachedIListPage update(CachedTerm term, CachedIListPage page)
          Updates the inverted list page associated with the specified term in the cache if a cached page exists for the term.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PAGE_SIZE

public static int DEFAULT_PAGE_SIZE
Default maximum number of items an inverted list page should store.

Constructor Detail

CachedRider

public CachedRider(Cache<CachedTerm,CachedIListPage> cache)
Constructor for the CachedRider object. Uses default inverted list page size.

Parameters:
cache - actual cache used for storing inverted list pages

CachedRider

public CachedRider(Cache<CachedTerm,CachedIListPage> cache,
                   int pageSize)
Constructor for the CachedRider object.

Parameters:
cache - actual cache used for storing inverted list pages
pageSize - maximum size of an inverted list page
Method Detail

resolve

public CachedIListPage resolve(CachedTerm term)
Return a new cached inverted list page of the specified term.

Specified by:
resolve in interface Resolver<CachedTerm,CachedIListPage>
Parameters:
term - term to create the inverted list page for
Returns:
new cached inverted list page for the specified term

put

public CachedIListPage put(CachedTerm term,
                           CachedIListPage page)
Adds a new inverted list page for the specified term to the cache. If the term was previously cached, it is removed at first. If the cache is full, a page is removed from the cache according to the current eviction policy.

Parameters:
term - term to add to the cache
page - inverted list page to map the term to
Returns:
previous inverted list page associated with the term or null if a previous mapping did not exists in the cache for the specified term

get

public CachedIListPage get(CachedTerm term)
Gets the inverted list page associated with the specified term from the cache if the term is cached, or the inverted list page returned by the resolver.

Parameters:
term - term to get the result for
Returns:
inverted list page associated with the term from the cache, or from the resolver if the term was not cached

remove

public CachedIListPage remove(CachedTerm term)
Removes the specified term and its page from the cache.

Parameters:
term - term to remove from the cache.
Returns:
inverted list page associated with the term, or null if the term was not cached

update

public CachedIListPage update(CachedTerm term,
                              CachedIListPage page)
Updates the inverted list page associated with the specified term in the cache if a cached page exists for the term.

Parameters:
term - term to change the result for
page - new inverted list page associated with the key
Returns:
previous associated page or null if the term is not cached

containsKey

public boolean containsKey(CachedTerm term)
Checks whether the specified term is cached.

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

openIList

public IListReader openIList(Barrel barrel,
                             java.lang.String term)
Gets a cached inverted list reader for the specified barrel and term.

Parameters:
barrel - barrel to get the inverted list from
term - term owning the requested inverted list
Returns:
cached inverted list reader

getCache

public Cache<CachedTerm,CachedIListPage> getCache()
Gets the actual cache used for storing inverted list pages.

Returns:
actual cache used for storing inverted list pages

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

hitRatio

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

Returns:
hit ratio of the cache

requests

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

Returns:
number of all submitted requests

resetCounters

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


size

public int size()
Returns the number of cached inverted list pages.

Returns:
number cached inverted list pages

getPostings

public long getPostings()
Returns the number of postings that the cached pages occupy.

Returns:
number of postings that the cached pages occupy

getCachedPostings

public long getCachedPostings()
Returns the actual number of cached postings.

Returns:
actual number of cached postings