forked from textileio/go-threads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.go
40 lines (31 loc) · 910 Bytes
/
cache.go
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
package lstoreds
// cache abstracts all methods we access from ARCCache, to enable alternate
// implementations such as a no-op one.
type cache interface {
Get(key interface{}) (value interface{}, ok bool)
Add(key, value interface{})
Remove(key interface{})
Contains(key interface{}) bool
Peek(key interface{}) (value interface{}, ok bool)
Keys() []interface{}
}
// noopCache is a dummy implementation that's used when the cache is disabled.
type noopCache struct {
}
var _ cache = (*noopCache)(nil)
func (*noopCache) Get(_ interface{}) (value interface{}, ok bool) {
return nil, false
}
func (*noopCache) Add(_, _ interface{}) {
}
func (*noopCache) Remove(_ interface{}) {
}
func (*noopCache) Contains(_ interface{}) bool {
return false
}
func (*noopCache) Peek(_ interface{}) (value interface{}, ok bool) {
return nil, false
}
func (*noopCache) Keys() (keys []interface{}) {
return keys
}