Package org.apache.myfaces.util.lang
Class ConcurrentLRUCache<K,V>
java.lang.Object
org.apache.myfaces.util.lang.ConcurrentLRUCache<K,V>
A LRU cache implementation based upon ConcurrentHashMap and other techniques to reduce
contention and synchronization overhead to utilize multiple CPU cores more effectively.
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.
See org.apache.solr.util.ConcurrentLRUCache- Since:
- solr 1.4
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static class
-
Constructor Summary
ConstructorsConstructorDescriptionConcurrentLRUCache
(int size, int lowerWatermark) ConcurrentLRUCache
(int upperWaterMark, int lowerWaterMark, int acceptableWatermark, int initialSize, boolean runCleanupThread, boolean runNewThreadForCleanup, ConcurrentLRUCache.EvictionListener<K, V> evictionListener) -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
void
destroy()
protected void
finalize()
getLatestAccessedItems
(int n) getMap()
getOldestAccessedItems
(int n) Returns 'n' number of oldest accessed entries present in this cache.getStats()
void
setAlive
(boolean live) int
size()
-
Constructor Details
-
ConcurrentLRUCache
public ConcurrentLRUCache(int upperWaterMark, int lowerWaterMark, int acceptableWatermark, int initialSize, boolean runCleanupThread, boolean runNewThreadForCleanup, ConcurrentLRUCache.EvictionListener<K, V> evictionListener) -
ConcurrentLRUCache
public ConcurrentLRUCache(int size, int lowerWatermark)
-
-
Method Details
-
setAlive
public void setAlive(boolean live) -
get
-
remove
-
put
-
getOldestAccessedItems
Returns 'n' number of oldest accessed entries present in this cache. This uses a TreeSet to collect the 'n' oldest items ordered by ascending last access time and returns a LinkedHashMap containing 'n' or less than 'n' entries.- Parameters:
n
- the number of oldest items needed- Returns:
- a LinkedHashMap containing 'n' or less than 'n' entries
-
getLatestAccessedItems
-
size
public int size() -
clear
public void clear() -
getMap
-
destroy
public void destroy() -
getStats
-
finalize
-