K
- 键类型V
- 值类型public class FIFOCache<K,V> extends AbstractCache<K,V>
元素不停的加入缓存直到缓存满为止,当缓存满时,清理过期缓存对象,清理后依旧满则删除先入的缓存(链表首部对象)
优点:简单快速
缺点:不灵活,不能保证最常用的对象总是被保留
cacheMap, capacity, existCustomTimeout, hitCount, keyLockMap, listener, missCount, timeout
Constructor and Description |
---|
FIFOCache(int capacity)
构造,默认对象不过期
|
FIFOCache(int capacity,
long timeout)
构造
|
Modifier and Type | Method and Description |
---|---|
protected int |
pruneCache()
先进先出的清理策略
先遍历缓存清理过期的缓存对象,如果清理后还是满的,则删除第一个缓存对象 |
cacheObjIterator, capacity, clear, containsKey, get, get, getHitCount, getMissCount, isEmpty, isFull, isPruneExpiredActive, iterator, keySet, onRemove, prune, put, put, remove, setListener, size, timeout, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public FIFOCache(int capacity)
capacity
- 容量public FIFOCache(int capacity, long timeout)
capacity
- 容量timeout
- 过期时长protected int pruneCache()
pruneCache
in class AbstractCache<K,V>
Copyright © 2021. All rights reserved.