org.apache.solr.util
Class ConcurrentLFUCache<K,V>

java.lang.Object
  extended by org.apache.solr.util.ConcurrentLFUCache<K,V>

public class ConcurrentLFUCache<K,V>
extends Object

A LFU cache implementation based upon ConcurrentHashMap.

This is not a terribly efficient implementation. The tricks used in the LRU version were not directly usable, perhaps it might be possible to rewrite them with LFU in mind.

This API is experimental and subject to change

Since:
solr 1.6

Nested Class Summary
static interface ConcurrentLFUCache.EvictionListener<K,V>
           
static class ConcurrentLFUCache.Stats
           
 
Constructor Summary
ConcurrentLFUCache(int size, int lowerWatermark)
           
ConcurrentLFUCache(int upperWaterMark, int lowerWaterMark, int acceptableSize, int initialSize, boolean runCleanupThread, boolean runNewThreadForCleanup, ConcurrentLFUCache.EvictionListener<K,V> evictionListener, boolean timeDecay)
           
 
Method Summary
 void clear()
           
 void destroy()
           
protected  void finalize()
           
 V get(K key)
           
 Map<K,V> getLeastUsedItems(int n)
          Returns 'n' number of least used entries present in this cache.
 Map<Object,org.apache.solr.util.ConcurrentLFUCache.CacheEntry<K,V>> getMap()
           
 Map<K,V> getMostUsedItems(int n)
          Returns 'n' number of most used entries present in this cache.
 ConcurrentLFUCache.Stats getStats()
           
 V put(K key, V val)
           
 V remove(K key)
           
 void setAlive(boolean live)
           
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConcurrentLFUCache

public ConcurrentLFUCache(int upperWaterMark,
                          int lowerWaterMark,
                          int acceptableSize,
                          int initialSize,
                          boolean runCleanupThread,
                          boolean runNewThreadForCleanup,
                          ConcurrentLFUCache.EvictionListener<K,V> evictionListener,
                          boolean timeDecay)

ConcurrentLFUCache

public ConcurrentLFUCache(int size,
                          int lowerWatermark)
Method Detail

setAlive

public void setAlive(boolean live)

get

public V get(K key)

remove

public V remove(K key)

put

public V put(K key,
             V val)

getLeastUsedItems

public Map<K,V> getLeastUsedItems(int n)
Returns 'n' number of least used entries present in this cache.

This uses a TreeSet to collect the 'n' least used items ordered by ascending hitcount and returns a LinkedHashMap containing 'n' or less than 'n' entries.

Parameters:
n - the number of items needed
Returns:
a LinkedHashMap containing 'n' or less than 'n' entries

getMostUsedItems

public Map<K,V> getMostUsedItems(int n)
Returns 'n' number of most used entries present in this cache.

This uses a TreeSet to collect the 'n' most used items ordered by descending hitcount and returns a LinkedHashMap containing 'n' or less than 'n' entries.

Parameters:
n - the number of items needed
Returns:
a LinkedHashMap containing 'n' or less than 'n' entries

size

public int size()

clear

public void clear()

getMap

public Map<Object,org.apache.solr.util.ConcurrentLFUCache.CacheEntry<K,V>> getMap()

destroy

public void destroy()

getStats

public ConcurrentLFUCache.Stats getStats()

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable


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