Class LFUCache<K,V>
java.lang.Object
org.miaixz.bus.core.cache.provider.AbstractCache<K,V>
org.miaixz.bus.core.cache.provider.StampedCache<K,V>
org.miaixz.bus.core.cache.provider.LFUCache<K,V>
- Type Parameters:
K- 键类型V- 值类型
- All Implemented Interfaces:
Serializable,Iterable<V>,Cache<K,V>
LFU(least frequently used) 最少使用率缓存
根据使用次数来判定对象是否被持续缓存
使用率是通过访问次数计算的。
当缓存满时清理过期对象。
清理后依旧满的情况下清除最少访问(访问计数最小)的对象并将其他对象的访问数减去这个最小访问数,以便新对象进入后可以公平计数。
- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Field Summary
Fields inherited from class org.miaixz.bus.core.cache.provider.StampedCache
lockFields inherited from class org.miaixz.bus.core.cache.provider.AbstractCache
cacheMap, capacity, existCustomTimeout, hitCount, keyLockMap, listener, missCount, timeout -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected int清理过期对象。 清理后依旧满的情况下清除最少访问(访问计数最小)的对象并将其他对象的访问数减去这个最小访问数,以便新对象进入后可以公平计数。Methods inherited from class org.miaixz.bus.core.cache.provider.StampedCache
cacheObjIterator, clear, containsKey, get, prune, put, removeMethods inherited from class org.miaixz.bus.core.cache.provider.AbstractCache
cacheObjIter, capacity, get, get, getHitCount, getMissCount, getWithoutLock, isEmpty, isFull, isPruneExpiredActive, iterator, keySet, onRemove, put, putWithoutLock, removeWithoutLock, setListener, size, timeout, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
LFUCache
public LFUCache(int capacity) 构造- Parameters:
capacity- 容量
-
LFUCache
public LFUCache(int capacity, long timeout) 构造- Parameters:
capacity- 容量timeout- 过期时长
-
-
Method Details
-
pruneCache
protected int pruneCache()清理过期对象。 清理后依旧满的情况下清除最少访问(访问计数最小)的对象并将其他对象的访问数减去这个最小访问数,以便新对象进入后可以公平计数。- Specified by:
pruneCachein classAbstractCache<K,V> - Returns:
- 清理个数
-