public class ConcurrentLFUCache<K,V> extends Object implements Cache<K,V>
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
Modifier and Type | Class and Description |
---|---|
static class |
ConcurrentLFUCache.CacheEntry<K,V> |
static interface |
ConcurrentLFUCache.EvictionListener<K,V> |
static class |
ConcurrentLFUCache.Stats |
Constructor and Description |
---|
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) |
Modifier and Type | Method and Description |
---|---|
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,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() |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
computeIfAbsent
public ConcurrentLFUCache(int upperWaterMark, int lowerWaterMark, int acceptableSize, int initialSize, boolean runCleanupThread, boolean runNewThreadForCleanup, ConcurrentLFUCache.EvictionListener<K,V> evictionListener, boolean timeDecay)
public ConcurrentLFUCache(int size, int lowerWatermark)
public void setAlive(boolean live)
public Map<K,V> getLeastUsedItems(int n)
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.
n
- the number of items neededpublic Map<K,V> getMostUsedItems(int n)
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.
n
- the number of items neededpublic int size()
public Map<Object,ConcurrentLFUCache.CacheEntry<K,V>> getMap()
public void destroy()
public ConcurrentLFUCache.Stats getStats()
Copyright © 2000-2019 Apache Software Foundation. All Rights Reserved.