Class FIFOCache<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.FIFOCache<K,V>
- Type Parameters:
K- 键类型V- 值类型
- All Implemented Interfaces:
Serializable,Iterable<V>,Cache<K,V>
FIFO(first in first out) 先进先出缓存.
元素不停的加入缓存直到缓存满为止,当缓存满时,清理过期缓存对象,清理后依旧满则删除先入的缓存(链表首部对象) 优点:简单快速 缺点:不灵活,不能保证最常用的对象总是被保留
- 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
-
FIFOCache
public FIFOCache(int capacity) 构造,默认对象不过期- Parameters:
capacity- 容量
-
FIFOCache
public FIFOCache(int capacity, long timeout) 构造- Parameters:
capacity- 容量timeout- 过期时长
-
-
Method Details
-
pruneCache
protected int pruneCache()先进先出的清理策略 先遍历缓存清理过期的缓存对象,如果清理后还是满的,则删除第一个缓存对象- Specified by:
pruneCachein classAbstractCache<K,V> - Returns:
- 清理数
-