Package com.xxl.tool.cache.impl
Class LRUCache<K,V>
java.lang.Object
com.xxl.tool.cache.impl.ReentrantCache<K,V>
com.xxl.tool.cache.impl.LRUCache<K,V>
- All Implemented Interfaces:
Cache<K,,V> Serializable
LRU (least recently used)最近最久未使用缓存
1、元素持续添加直到存满,触发 清理全部过期对象;
2、清理后缓存仍存满时,最久未被使用的对象将被移除;
(此缓存基于LinkedHashMap,因此当被缓存的对象每被访问一次,这个对象的key就到链表头部)
3、优劣势:
- 优势:简单、速度快;经常使用的对象,不会被被移除缓存;
- 劣势:不能很快的访问缓存中不常用的对象;
- See Also:
-
Field Summary
Fields inherited from class com.xxl.tool.cache.impl.ReentrantCache
cacheMap, capacity, expireType, hitCount, listener, loader, missCount, timeout, writeLockCount, writeLockMap -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class com.xxl.tool.cache.impl.ReentrantCache
asMap, capacity, clear, containsKey, get, get, getIfPresent, hitCount, isEmpty, isFull, missCount, onRemove, prune, put, remove, removeWithoutLock, setListener, setLoader, size, timeout, toString
-
Constructor Details
-
LRUCache
public LRUCache(int capacity, long timeout, boolean expireType)
-
-
Method Details
-
doPrune
protected int doPrune()只 清理全部过期对象,LRU的实现会交给LinkedHashMap- Specified by:
doPrunein classReentrantCache<K,V> - Returns:
- 清理数据量
-