类 LRUCache
java.lang.Object
java.util.AbstractMap<String,net.sohelp.boot.admin.core.db.cache.LRUCache.ExpireNode<Object>>
java.util.HashMap<String,net.sohelp.boot.admin.core.db.cache.LRUCache.ExpireNode<Object>>
java.util.LinkedHashMap<String,net.sohelp.boot.admin.core.db.cache.LRUCache.ExpireNode<Object>>
net.sohelp.boot.admin.core.db.cache.LRUCache
- 所有已实现的接口:
Serializable,Cloneable,Map<String,,net.sohelp.boot.admin.core.db.cache.LRUCache.ExpireNode<Object>> SequencedMap<String,net.sohelp.boot.admin.core.db.cache.LRUCache.ExpireNode<Object>>
public class LRUCache
extends LinkedHashMap<String,net.sohelp.boot.admin.core.db.cache.LRUCache.ExpireNode<Object>>
LRU缓存实现,基于LinkedHashMap并支持过期时间和最大容量限制。
提供按命名空间管理缓存项的能力,并通过读写锁保证线程安全。
- 作者:
- mxd
- 另请参阅:
-
嵌套类概要
从类继承的嵌套类/接口 java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明void删除指定命名空间下的所有缓存项。获取缓存中的数据,若不存在或已过期则返回null。void向缓存中添加数据,默认使用全局过期时间。void向缓存中添加数据,可指定自定义过期时间。protected booleanremoveEldestEntry(Map.Entry<String, net.sohelp.boot.admin.core.db.cache.LRUCache.ExpireNode<Object>> eldest) 当缓存大小超过设定容量时触发移除最老元素的操作。从类继承的方法 java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, newLinkedHashMap, putFirst, putLast, replaceAll, reversed, sequencedEntrySet, sequencedKeySet, sequencedValues, values从类继承的方法 java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, newHashMap, put, putAll, putIfAbsent, remove, remove, replace, replace, size从类继承的方法 java.util.AbstractMap
equals, hashCode, toString从接口继承的方法 java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size从接口继承的方法 java.util.SequencedMap
firstEntry, lastEntry, pollFirstEntry, pollLastEntry
-
构造器详细资料
-
LRUCache
public LRUCache(int capacity, long expire) 构造一个默认的SQL缓存实例,使用LRU缓存策略。- 参数:
capacity- 缓存的最大容量expire- 缓存项的过期时间(单位:毫秒)
-
-
方法详细资料
-
put
向缓存中添加数据,默认使用全局过期时间。- 参数:
name- 命名空间名称key- 数据键value- 数据值
-
put
向缓存中添加数据,可指定自定义过期时间。- 参数:
name- 命名空间名称key- 数据键value- 数据值ttl- 自定义过期时间(单位:毫秒)
-
get
获取缓存中的数据,若不存在或已过期则返回null。- 参数:
name- 命名空间名称key- 数据键- 返回:
- 缓存数据值,如果未找到或已过期则返回null
-
delete
删除指定命名空间下的所有缓存项。- 参数:
name- 命名空间名称
-
removeEldestEntry
protected boolean removeEldestEntry(Map.Entry<String, net.sohelp.boot.admin.core.db.cache.LRUCache.ExpireNode<Object>> eldest) 当缓存大小超过设定容量时触发移除最老元素的操作。 若设置了全局过期时间,则在移除之前先清理已过期的数据。- 覆盖:
removeEldestEntry在类中LinkedHashMap<String,net.sohelp.boot.admin.core.db.cache.LRUCache.ExpireNode<Object>> - 参数:
eldest- 最近最少使用的条目- 返回:
- 是否需要移除此条目
-