org.apache.lucene.util
Class DoubleBarrelLRUCache<K extends DoubleBarrelLRUCache.CloneableKey,V>

java.lang.Object
  extended by org.apache.lucene.util.DoubleBarrelLRUCache<K,V>

public final class DoubleBarrelLRUCache<K extends DoubleBarrelLRUCache.CloneableKey,V>
extends Object

Simple concurrent LRU cache, using a "double barrel" approach where two ConcurrentHashMaps record entries.

At any given time, one hash is primary and the other is secondary. get(K) first checks primary, and if that's a miss, checks secondary. If secondary has the entry, it's promoted to primary (NOTE: the key is cloned at this point). Once primary is full, the secondary is cleared and the two are swapped.

This is not as space efficient as other possible concurrent approaches (see LUCENE-2075): to achieve perfect LRU(N) it requires 2*N storage. But, this approach is relatively simple and seems in practice to not grow unbounded in size when under hideously high load.

NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

Nested Class Summary
static class DoubleBarrelLRUCache.CloneableKey
          Object providing clone(); the key class must subclass this.
 
Constructor Summary
DoubleBarrelLRUCache(int maxSize)
           
 
Method Summary
 V get(K key)
           
 void put(K key, V value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DoubleBarrelLRUCache

public DoubleBarrelLRUCache(int maxSize)
Method Detail

get

public V get(K key)

put

public void put(K key,
                V value)


Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.