-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnode_cache.go
26 lines (23 loc) · 861 Bytes
/
node_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
package mast
import lru "github.com/hashicorp/golang-lru"
// NodeCache caches the immutable nodes from a remote storage source.
// It is also used to avoid re-storing nodes, so care should be taken
// to switch/invalidate NodeCache when the Persist is changed.
//
type NodeCache interface {
// Add adds a freshly-persisted node to the cache.
Add(key, value interface{})
// Contains indicates the node with the given key has already been persisted.
Contains(key interface{}) bool
// Get retrieves the already-deserialized node with the given hash, if cached.
Get(key interface{}) (value interface{}, ok bool)
}
// NewNodeCache creates a new LRU-based node cache of the given size. One cache
// can be shared by any number of trees.
func NewNodeCache(size int) NodeCache {
cache, err := lru.NewARC(size)
if err != nil {
panic(err)
}
return cache
}