Class CacheLruK<K,V>
- java.lang.Object
-
- com.gitee.apanlh.util.cache.local.CacheAbstract<K,V>
-
- com.gitee.apanlh.util.cache.local.CacheLruK<K,V>
-
- Type Parameters:
K- 建类型V- 值类型
- All Implemented Interfaces:
CacheClear,CacheProvider
public class CacheLruK<K,V> extends CacheAbstract<K,V>
CacheLRU-K
淘汰最久未使用
解决LRU算法的缓存污染- Author:
- Pan
-
-
Constructor Summary
Constructors Constructor Description CacheLruK()默认构造函数
历史访问列表256最大容量
LRU缓存列表128最大容量
K值为2次CacheLruK(int capacity)默认构造函数
LRU缓存列表容量与历史访问列表一致
默认K值为2次CacheLruK(int historyCapacity, int lruCapacity)构造函数
自定义历史列表容量及LRU列表容量CacheLruK(int historyCapacity, int lruCapacity, int k)构造函数
自定义历史列表最大容量、LRU列表最大容量、K值
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()清理历史缓存及LRU缓存
两者缓存都会清空voidclearUnlock()将Map清空
未加锁booleanequals(Object o)CacheFifo<K,CacheObject<V>>getHistory()获取历史缓存intgetHistorySize()获取历史缓存长度intgetHit()获取命中率CacheLru<K,CacheObject<V>>getLru()获取LRU缓存intgetLruSize()获取LRU缓存长度inthashCode()intsize()获取大小StringtoString()-
Methods inherited from class com.gitee.apanlh.util.cache.local.CacheAbstract
clearCache, containsKey, containsKeyUnlocked, containsValue, containsValueUnlocked, entrySet, get, getMap, getUnlocked, isEmpty, keySet, put, putUnlocked, remove, remove, removeUnlocked, removeUnlocked, values
-
-
-
-
Constructor Detail
-
CacheLruK
public CacheLruK()
默认构造函数
历史访问列表256最大容量
LRU缓存列表128最大容量
K值为2次
-
CacheLruK
public CacheLruK(int capacity)
默认构造函数
LRU缓存列表容量与历史访问列表一致
默认K值为2次- Parameters:
capacity- 最大容量
-
CacheLruK
public CacheLruK(int historyCapacity, int lruCapacity)构造函数
自定义历史列表容量及LRU列表容量- Parameters:
historyCapacity- 历史访问列表最大容量lruCapacity- LRU缓存列表最大容量
-
CacheLruK
public CacheLruK(int historyCapacity, int lruCapacity, int k)构造函数
自定义历史列表最大容量、LRU列表最大容量、K值- Parameters:
historyCapacity- 历史访问列表最大容量lruCapacity- LRU缓存列表最大容量k- K次数
-
-
Method Detail
-
size
public int size()
Description copied from class:CacheAbstract获取大小- Overrides:
sizein classCacheAbstract<K,V>- Returns:
- int
-
clear
public void clear()
清理历史缓存及LRU缓存
两者缓存都会清空- Overrides:
clearin classCacheAbstract<K,V>
-
clearUnlock
public void clearUnlock()
Description copied from class:CacheAbstract将Map清空
未加锁- Overrides:
clearUnlockin classCacheAbstract<K,V>
-
getHistorySize
public int getHistorySize()
获取历史缓存长度- Returns:
- int
-
getLruSize
public int getLruSize()
获取LRU缓存长度- Returns:
- int
-
getHistory
public CacheFifo<K,CacheObject<V>> getHistory()
获取历史缓存- Returns:
- CacheFifo
-
getLru
public CacheLru<K,CacheObject<V>> getLru()
获取LRU缓存- Returns:
- CacheLru
-
getHit
public int getHit()
Description copied from class:CacheAbstract获取命中率- Specified by:
getHitin interfaceCacheProvider- Overrides:
getHitin classCacheAbstract<K,V>- Returns:
- int
-
equals
public boolean equals(Object o)
- Overrides:
equalsin classCacheAbstract<K,V>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classCacheAbstract<K,V>
-
-