热门

最新

红包

立Flag

投票

同城

我的

发布
as4589sd
阿啄debugIT
6 年前
trueas4589sd

guava缓存创建分为两种,一种是CacheLoader,另一种则是callback方式

CacheLoader:
LoadingCache<String,String> cahceBuilder=CacheBuilder
.newBuilder()
.build(new CacheLoader<String, String>(){
@Override
public String load(String key) throws Exception {
String strProValue="hello "+key+"!";
return strProValue;
}
});
System.out.println(cahceBuilder.apply("begincode"));
System.out.println(cahceBuilder.get("begincode"));
api中推荐使用get方法获取值

callback方式:
Cache<String, String> cache = CacheBuilder.newBuilder().maximumSize(1000).build();
String resultVal = cache.get("code", new Callable<String>() {
public String call() {
String strProValue="begin "+"code"+"!";
return strProValue;
}
});
System.out.println("value : " + resultVal);

CSDN App 扫码分享
分享
评论
12
打赏
  • 复制链接
  • 举报
下一条:
删除aotucad注册码后这些不能用了,笔记本触屏也用不了了,有没有大佬想想给个问题思路呀!
立即登录