Class TimedCache<K,V>
java.lang.Object
com.sure.tool.cache.TimedCache<K,V>
- Type Parameters:
K- 键类型V- 值类型
- All Implemented Interfaces:
Cache<K,V>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()清空缓存。booleancontainsKey(K key) 是否包含键(已过期视为不存在)。读取缓存值(过期返回null并移除)。longgetRemainingTime(K key) 获取键的剩余存活时间。booleanisEmpty()是否为空。intprune()主动清理全部过期条目。写入缓存(使用默认 TTL)。写入缓存并指定 TTL。移除缓存项。intsize()缓存项数量。
-
Constructor Details
-
TimedCache
public TimedCache(long defaultTimeout) 创建定时缓存。- Parameters:
defaultTimeout- 默认存活时间(毫秒),<=0 表示不过期
-
-
Method Details
-
put
-
put
-
get
-
remove
-
clear
-
size
-
containsKey
-
isEmpty
-
prune
public int prune()主动清理全部过期条目。- Returns:
- 清理数量
-
getRemainingTime
获取键的剩余存活时间。- Parameters:
key- 键- Returns:
- 剩余毫秒:不存在或已过期返回 0;永不过期返回
Long.MAX_VALUE
-