-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuguicache.puml
99 lines (80 loc) · 1.78 KB
/
fuguicache.puml
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
@startuml
'https://plantuml.com/class-diagram
class lru.cache {
maxBytes int64
nbytes int64
ll *list.List
cache map[string]*list.Element
OnEvicted func(key string, value Value)
Get(key string)
RemoveOldest()
Add(key string, value Value)
Len()
}
class ByteView {
b []byte
Len()
ByteSlice() []byte
String() string
}
ByteView --o lru.cache
class cache {
mu sync.Mutex
lru *lru.Cache
cacheBytes int64
}
cache *-- lru.cache
class Group {
name string
getter Getter
mainCache cache
peers PeerPicker
loader *singleflight.Group
Get(key string) (ByteView, error)
load(key string) (value ByteView, err error)
getLocally(key string) (ByteView, error)
getFromPeer(peer PeerGetter, key string) (ByteView, error)
populateCache(key string, value ByteView)
}
Group *-- cache
Group *-- PeerPicker
class HTTPPool {
self string
basePath string
my sync.Mutex
peers *consistenthash.Map
httpGetters map[string]*httpGetter
ServeHTTP(w http.ResponseWriter, r *http.Request)
Set(peers ...string)
PickPeer(key string) (PeerGetter, bool)
}
HTTPPool --> Group
HTTPPool *-- consistenthash.Map
HTTPPool *-- httpGetter
HTTPPool --|> PeerPicker
class httpGetter {
baseURL string
Get(group string, key string) ([]byte, error)
}
httpGetter --|> PeerGetter
class consistenthash.Map {
hash Hash
replicas int
keys []int // Sorted
hashMap map[int]string
Add(keys ...string)
Get(key string) string
}
interface PeerPicker {
PickPeer(key string) (peer PeerGetter, ok bool)
}
interface PeerGetter {
Get(group string, key string) ([]byte, error)
}
class singleflight.Group {
mu sync.Mutex
m map[string]*call
Do(key string, fn func() (interface{}, error)) (interface{}, error)
}
singleflight.Group --* Group
@enduml