标签
缓存
工具
字数
69 字
阅读时间
1 分钟
引入依赖
compile 'com.google.guava:guava:28.0-jre'缓存
java
private LoadingCache<String, ConstantDict<?>> cache;
cache = CacheBuilder.newBuilder()
.expireAfterAccess(5, TimeUnit.MINUTES)//5分钟未使用删除缓存
.expireAfterWrite(30, TimeUnit.MINUTES)//30分钟强制刷新
.build(new CacheLoader<String, ConstantDict<?>>() {
@Override
public ConstantDict<?> load(String key) throws Exception {
//加载数据
return loadDict(key);
}
});
//cache.get()获取数据。