-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp2.java
More file actions
37 lines (32 loc) · 898 Bytes
/
Copy pathApp2.java
File metadata and controls
37 lines (32 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
public class App2 {
public static void main(String[] args) {
//
CacheLoader<String,String> loader;
loader=new CacheLoader<String,String>(){
@Override
public String load(String key) throws Exception {
//
return key.toUpperCase();
}
};
//
LoadingCache<String,String> cache;
//
cache= CacheBuilder.newBuilder().maximumSize(3).build(loader);
//
cache.getUnchecked("first");
cache.getUnchecked("second");
cache.getUnchecked("third");
cache.getUnchecked("forth");
//
System.out.println(" cache缓存的大小是: "+cache.size());
//
System.out.println("获取first键的值 "+cache.getIfPresent("first"));
//
System.out.println("获取的forth键的值 "+cache.getIfPresent("forth"));
}
}