forked from hellokaton/write-readable-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample2.java
More file actions
54 lines (45 loc) · 991 Bytes
/
Copy pathExample2.java
File metadata and controls
54 lines (45 loc) · 991 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package chapter_14;
/**
* 缓存设计
* <p>
* 读取 a.txt
* 读取 a.txt
* 读取 a.txt
* 读取 b.txt
* 读取 b.txt
* 读取 c.txt
* 读取 d.txt
* 读取 d.txt
*
* @author biezhi
* @date 2018/9/24
*/
public class Example2 {
private DiskText lastUsed;
// 加载磁盘文件
public DiskText loadDiskText(String key) {
// 从本地加载
return new DiskText(key, "");
}
// 根据 key 获取磁盘文件
public DiskText lookUp(String key) {
if (lastUsed == null || !lastUsed.key().equals(key)) {
lastUsed = loadDiskText(key);
}
return lastUsed;
}
class DiskText {
private String key;
private String value;
public DiskText(String key, String value) {
this.key = key;
this.value = value;
}
public String value() {
return value;
}
public String key() {
return key;
}
}
}