public class ConcurrentLRUCache<K,V> extends Object implements Cache<K,V>, Accountable
Note that the implementation does not follow a true LRU (least-recently-used) eviction strategy. Instead it strives to remove least recently used items but when the initial cleanup does not remove enough items to reach the 'acceptableWaterMark' limit, it can remove more items forcefully regardless of access order.
Modifier and Type | Class and Description |
---|---|
static class |
ConcurrentLRUCache.CacheEntry<K,V> |
static interface |
ConcurrentLRUCache.EvictionListener<K,V> |
static class |
ConcurrentLRUCache.Stats |
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) |
ConcurrentLRUCache(int upperWaterMark,
int lowerWaterMark,
int acceptableWatermark,
int initialSize,
boolean runCleanupThread,
boolean runNewThreadForCleanup,
ConcurrentLRUCache.EvictionListener<K,V> evictionListener,
int maxIdleTimeSec) |
ConcurrentLRUCache(long ramLowerWatermark,
long ramUpperWatermark,
boolean runCleanupThread,
ConcurrentLRUCache.EvictionListener<K,V> evictionListener) |
ConcurrentLRUCache(long ramLowerWatermark,
long ramUpperWatermark,
boolean runCleanupThread,
ConcurrentLRUCache.EvictionListener<K,V> evictionListener,
int maxIdleTimeSec) |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
V |
computeIfAbsent(K key,
Function<? super K,? extends V> mappingFunction) |
void |
destroy() |
protected void |
finalize() |
V |
get(K key) |
Collection<Accountable> |
getChildResources() |
Map<K,V> |
getLatestAccessedItems(int n) |
Map<Object,ConcurrentLRUCache.CacheEntry<K,V>> |
getMap() |
Map<K,V> |
getOldestAccessedItems(int n)
Returns 'n' number of oldest accessed entries present in this cache.
|
ConcurrentLRUCache.Stats |
getStats() |
void |
markAndSweep()
Removes items from the cache to bring the size down
to an acceptable value.
|
V |
put(K key,
V val) |
V |
putCacheEntry(ConcurrentLRUCache.CacheEntry<K,V> e)
Visible for testing to create synthetic cache entries.
|
long |
ramBytesUsed() |
V |
remove(K key) |
void |
setAcceptableWaterMark(int acceptableWaterMark) |
void |
setAlive(boolean live) |
void |
setLowerWaterMark(int lowerWaterMark) |
void |
setMaxIdleTime(int maxIdleTime) |
void |
setRamLowerWatermark(long ramLowerWatermark) |
void |
setRamUpperWatermark(long ramUpperWatermark) |
void |
setRunCleanupThread(boolean runCleanupThread) |
void |
setUpperWaterMark(int upperWaterMark) |
int |
size() |
public ConcurrentLRUCache(long ramLowerWatermark, long ramUpperWatermark, boolean runCleanupThread, ConcurrentLRUCache.EvictionListener<K,V> evictionListener)
public ConcurrentLRUCache(long ramLowerWatermark, long ramUpperWatermark, boolean runCleanupThread, ConcurrentLRUCache.EvictionListener<K,V> evictionListener, int maxIdleTimeSec)
public ConcurrentLRUCache(int upperWaterMark, int lowerWaterMark, int acceptableWatermark, int initialSize, boolean runCleanupThread, boolean runNewThreadForCleanup, ConcurrentLRUCache.EvictionListener<K,V> evictionListener)
public ConcurrentLRUCache(int upperWaterMark, int lowerWaterMark, int acceptableWatermark, int initialSize, boolean runCleanupThread, boolean runNewThreadForCleanup, ConcurrentLRUCache.EvictionListener<K,V> evictionListener, int maxIdleTimeSec)
public ConcurrentLRUCache(int size, int lowerWatermark)
public void setAlive(boolean live)
public void setUpperWaterMark(int upperWaterMark)
public void setLowerWaterMark(int lowerWaterMark)
public void setAcceptableWaterMark(int acceptableWaterMark)
public void setRamUpperWatermark(long ramUpperWatermark)
public void setRamLowerWatermark(long ramLowerWatermark)
public void setMaxIdleTime(int maxIdleTime)
public void setRunCleanupThread(boolean runCleanupThread)
public V computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
computeIfAbsent
in interface Cache<K,V>
public V putCacheEntry(ConcurrentLRUCache.CacheEntry<K,V> e)
public void markAndSweep()
Visible for unit testing.
public Map<K,V> getOldestAccessedItems(int n)
n
- the number of oldest items neededpublic int size()
public Map<Object,ConcurrentLRUCache.CacheEntry<K,V>> getMap()
public void destroy()
public ConcurrentLRUCache.Stats getStats()
protected void finalize() throws Throwable
public long ramBytesUsed()
ramBytesUsed
in interface Accountable
public Collection<Accountable> getChildResources()
getChildResources
in interface Accountable
Copyright © 2000-2019 Apache Software Foundation. All Rights Reserved.