jdbm.helper
Class LRUCache<K,V>

java.lang.Object
  extended by jdbm.helper.LRUCache<K,V>

public class LRUCache<K,V>
extends Object

This class implements a versioned lru cache. Entries in the cache are identified with a key. When clients get a reference to the an entry, they point to the same object. Hence when the client wants to update and put a new version of the entry to the cache, he should not modify the object it got through the get interface (might copy on write). As new versions of the entries are put, cache maintains the previous versions of the entry. CLients specify the version of the cache entry they want to read. Clients are supposed to update the minimum read version the clients might request so that cache can purge older versions of data. For now, this class assumes clients make sure that put operations are serialized.

Author:
Apache Directory Project

Constructor Summary
LRUCache(EntryIO<K,V> entryIO, int cacheSize)
           
 
Method Summary
 void advanceMinReadVersion(long minVersion)
          Called as the minimum version that readers will use advances.
 V get(K key, long version, Serializer serializer)
          Finds and returns the entry corresponding to the given key and version.
 void put(K key, V value, long newVersion, Serializer serializer, boolean neverReplace)
          Updates the entry identified with the key with the new value.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LRUCache

public LRUCache(EntryIO<K,V> entryIO,
                int cacheSize)
Method Detail

advanceMinReadVersion

public void advanceMinReadVersion(long minVersion)
Called as the minimum version that readers will use advances. This lets cache get rid of the older versions of entries.

Parameters:
minVersion - mimimum version that will be read from the cache

put

public void put(K key,
                V value,
                long newVersion,
                Serializer serializer,
                boolean neverReplace)
         throws IOException,
                CacheEvictionException
Updates the entry identified with the key with the new value.

Parameters:
key - identifier of the entry
value - new value of the entry
newVersion - version of the new value
serializer - used in case of IO
neverReplace - true if caller wants to always keep the entry in cache
Throws:
IOException, - CacheEvictionException
IOException
CacheEvictionException

get

public V get(K key,
             long version,
             Serializer serializer)
      throws IOException
Finds and returns the entry corresponding to the given key and version.

Parameters:
key - the identifier for the entry
version - version the caller want to read
serializer - used in case of IO
Returns:
value read
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2003-2012 The Apache Software Foundation. All Rights Reserved.