public class ConcurrentLRUCache<K,V>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
ConcurrentLRUCache.CacheEntry<K,V> |
private static class |
ConcurrentLRUCache.CleanupThread |
static interface |
ConcurrentLRUCache.EvictionListener<K,V> |
private static class |
ConcurrentLRUCache.PQueue |
static class |
ConcurrentLRUCache.Stats |
Modifier and Type | Field and Description |
---|---|
private int |
acceptableWaterMark |
private ConcurrentLRUCache.CleanupThread |
cleanupThread |
private ConcurrentLRUCache.EvictionListener<K,V> |
evictionListener |
private boolean |
isCleaning |
private boolean |
isDestroyed |
private boolean |
islive |
private static org.slf4j.Logger |
log |
private int |
lowerWaterMark |
private java.util.concurrent.ConcurrentHashMap<java.lang.Object,ConcurrentLRUCache.CacheEntry<K,V>> |
map |
private java.util.concurrent.locks.ReentrantLock |
markAndSweepLock |
private boolean |
newThreadForCleanup |
private long |
oldestEntry |
private ConcurrentLRUCache.Stats |
stats |
private int |
upperWaterMark |
Constructor and Description |
---|
ConcurrentLRUCache(int size,
int lowerWatermark) |
ConcurrentLRUCache(int upperWaterMark,
int lowerWaterMark,
int acceptableWatermark,
int initialSize,
boolean runCleanupThread,
boolean runNewThreadForCleanup,
ConcurrentLRUCache.EvictionListener<K,V> evictionListener) |
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> |
getLatestAccessedItems(int n) |
java.util.Map<java.lang.Object,ConcurrentLRUCache.CacheEntry<K,V>> |
getMap() |
java.util.Map<K,V> |
getOldestAccessedItems(int n)
Returns 'n' number of oldest accessed entries present in this cache.
|
ConcurrentLRUCache.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,ConcurrentLRUCache.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 ConcurrentLRUCache.Stats stats
private final int acceptableWaterMark
private long oldestEntry
private final ConcurrentLRUCache.EvictionListener<K,V> evictionListener
private ConcurrentLRUCache.CleanupThread cleanupThread
private boolean isDestroyed
public ConcurrentLRUCache(int upperWaterMark, int lowerWaterMark, int acceptableWatermark, int initialSize, boolean runCleanupThread, boolean runNewThreadForCleanup, ConcurrentLRUCache.EvictionListener<K,V> evictionListener)
public ConcurrentLRUCache(int size, int lowerWatermark)
public void setAlive(boolean live)
private void markAndSweep()
private void evictEntry(K key)
public java.util.Map<K,V> getOldestAccessedItems(int n)
n
- the number of oldest items neededpublic int size()
public void clear()
public java.util.Map<java.lang.Object,ConcurrentLRUCache.CacheEntry<K,V>> getMap()
public void destroy()
public ConcurrentLRUCache.Stats getStats()
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable