public class ConcurrentLFUCache<K,V>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
ConcurrentLFUCache.CacheEntry<K,V> |
private static class |
ConcurrentLFUCache.CleanupThread |
static interface |
ConcurrentLFUCache.EvictionListener<K,V> |
static class |
ConcurrentLFUCache.Stats |
Modifier and Type | Field and Description |
---|---|
private int |
acceptableWaterMark |
private ConcurrentLFUCache.CleanupThread |
cleanupThread |
private ConcurrentLFUCache.EvictionListener<K,V> |
evictionListener |
private boolean |
isCleaning |
private boolean |
isDestroyed |
private boolean |
islive |
private static org.slf4j.Logger |
log |
private int |
lowerWaterMark |
private long |
lowHitCount |
private java.util.concurrent.ConcurrentHashMap<java.lang.Object,ConcurrentLFUCache.CacheEntry<K,V>> |
map |
private java.util.concurrent.locks.ReentrantLock |
markAndSweepLock |
private boolean |
newThreadForCleanup |
private ConcurrentLFUCache.Stats |
stats |
private boolean |
timeDecay |
private int |
upperWaterMark |
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() |
private void |
evictEntry(K key) |
protected void |
finalize() |
V |
get(K key) |
java.util.Map<K,V> |
getLeastUsedItems(int n)
Returns 'n' number of least used entries present in this cache.
|
java.util.Map<java.lang.Object,ConcurrentLFUCache.CacheEntry<K,V>> |
getMap() |
java.util.Map<K,V> |
getMostUsedItems(int n)
Returns 'n' number of most used entries present in this cache.
|
ConcurrentLFUCache.Stats |
getStats() |
private void |
markAndSweep()
Removes items from the cache to bring the size down
to an acceptable value ('acceptableWaterMark').
|
V |
put(K key,
V val) |
V |
remove(K key) |
void |
setAlive(boolean live) |
int |
size() |
private static org.slf4j.Logger log
private final java.util.concurrent.ConcurrentHashMap<java.lang.Object,ConcurrentLFUCache.CacheEntry<K,V>> map
private final int upperWaterMark
private final int lowerWaterMark
private final java.util.concurrent.locks.ReentrantLock markAndSweepLock
private boolean isCleaning
private final boolean newThreadForCleanup
private volatile boolean islive
private final ConcurrentLFUCache.Stats stats
private final int acceptableWaterMark
private long lowHitCount
private final ConcurrentLFUCache.EvictionListener<K,V> evictionListener
private ConcurrentLFUCache.CleanupThread cleanupThread
private final boolean timeDecay
private boolean isDestroyed
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)
private void markAndSweep()
private void evictEntry(K key)
public java.util.Map<K,V> getLeastUsedItems(int n)
n
- the number of items neededpublic java.util.Map<K,V> getMostUsedItems(int n)
n
- the number of items neededpublic int size()
public void clear()
public java.util.Map<java.lang.Object,ConcurrentLFUCache.CacheEntry<K,V>> getMap()
public void destroy()
public ConcurrentLFUCache.Stats getStats()
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable