Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TimeMapCache

fybug edited this page Dec 17, 2020 · 2 revisions

内部使用 LinkedHashMap 实现的基于时间进行管理的缓存工具。

在每次数据获取时会检查时间是否已经过期,也可启动线程定期扫描热度最低的几个数据是否过期。

建议使用 build() 方法获取 Build 工具进行构造。

使用 getData(key)putData(key, val) 方法来获取和设置缓存数据,可以同时指定新的缓存过期的时间。

设置数据时可以指定回收事件接口,回收事件在单独的线程池中执行

使用示例

TimeMapCache<String, Object> cache = TimeMapCache.build(String.class, Object.class)
 // 500 毫秒扫描一次
 .scarrentime(500)
 // 扫描热度最低的 20 个数据
 .scarrenNum(20).build();
// -> null
cache.getData("a");
// 缓存数据,并设置该数据 1000 毫秒后过期
cache.putData("a", new Object(), 1000);
// -> Object,同时重新设置在当前 2000 毫秒后过期
cache.getData("a", 2000);

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /