net.ontopia.utils
Class CachedIndex

java.lang.Object
  extended by net.ontopia.utils.CachedIndex
All Implemented Interfaces:
LookupIndexIF

public class CachedIndex
extends java.lang.Object
implements LookupIndexIF

INTERNAL: A LookupIndexIF which uses another, slower, LookupIndexIF as a fallback and caches the values attached to the most commonly requested keys using an LRU strategy. There is a maximum number of keys that can be stored in the index and the index will automatically prune the less-used keys to avoid the index growing above this maximum size.


Constructor Summary
CachedIndex(LookupIndexIF fallback)
          Creates an index with the given fallback and default settings.
CachedIndex(LookupIndexIF fallback, boolean nulls)
          Creates an index with the given fallback, default settings and the specified nulls setting.
CachedIndex(LookupIndexIF fallback, int max, int size, boolean nulls)
          Creates an index with the given fallback and settings.
 
Method Summary
 java.lang.Object get(java.lang.Object key)
           
 int getKeyNumber()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 java.lang.Object remove(java.lang.Object key)
           
 void writeReport()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedIndex

public CachedIndex(LookupIndexIF fallback)
Creates an index with the given fallback and default settings.


CachedIndex

public CachedIndex(LookupIndexIF fallback,
                   boolean nulls)
Creates an index with the given fallback, default settings and the specified nulls setting.


CachedIndex

public CachedIndex(LookupIndexIF fallback,
                   int max,
                   int size,
                   boolean nulls)
Creates an index with the given fallback and settings.

Parameters:
fallback - The index to ask if the value is not found in the cache.
max - The max number of keys to store in the cache (default: 10000).
size - The initial size of the cache.
nulls - Store null values retrieved from fallback.
Method Detail

get

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

put

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

remove

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

getKeyNumber

public int getKeyNumber()

writeReport

public void writeReport()


Copyright © 2000-2009 Ontopia.