net.ontopia.utils
Class CachedIndex<K,E>

java.lang.Object
  extended by net.ontopia.utils.CachedIndex<K,E>
All Implemented Interfaces:
LookupIndexIF<K,E>

public class CachedIndex<K,E>
extends java.lang.Object
implements LookupIndexIF<K,E>

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.


Nested Class Summary
 class CachedIndex.Entry<A,B>
           
 
Constructor Summary
CachedIndex(LookupIndexIF<K,E> fallback)
          Creates an index with the given fallback and default settings.
CachedIndex(LookupIndexIF<K,E> fallback, boolean nulls)
          Creates an index with the given fallback, default settings and the specified nulls setting.
CachedIndex(LookupIndexIF<K,E> fallback, int max, int size, boolean nulls)
          Creates an index with the given fallback and settings.
 
Method Summary
 E get(K key)
           
 int getKeyNumber()
           
protected  void prune()
          Removes some of the keys in the cache, keeping only the most frequently requested keys.
 E put(K key, E value)
           
 E remove(K key)
           
 void writeReport()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedIndex

public CachedIndex(LookupIndexIF<K,E> fallback)
Creates an index with the given fallback and default settings.


CachedIndex

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


CachedIndex

public CachedIndex(LookupIndexIF<K,E> 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 E get(K key)
Specified by:
get in interface LookupIndexIF<K,E>

put

public E put(K key,
             E value)
Specified by:
put in interface LookupIndexIF<K,E>

remove

public E remove(K key)
Specified by:
remove in interface LookupIndexIF<K,E>

getKeyNumber

public int getKeyNumber()

writeReport

public void writeReport()

prune

protected void prune()
Removes some of the keys in the cache, keeping only the most frequently requested keys.



Copyright © 2000-2012 Ontopia.