-
Notifications
You must be signed in to change notification settings - Fork 880
Expand file tree
/
Copy pathcache.go
More file actions
47 lines (38 loc) · 1.41 KB
/
cache.go
File metadata and controls
47 lines (38 loc) · 1.41 KB
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
package dbcache
import (
"github.com/sei-protocol/sei-chain/sei-db/db_engine/types"
)
// Cache describes a cache capable of being used by a FlatKV store.
type Cache interface {
// Get returns the value for the given key, or (nil, false) if not found.
Get(
// The entry to fetch.
key []byte,
// If true, the LRU queue will be updated. If false, the LRU queue will not be updated.
// Useful for when an operation is performed multiple times in close succession on the same key,
// since it requires non-zero overhead to do so with little benefit.
updateLru bool,
) ([]byte, bool, error)
// Perform a batch read operation. Given a map of keys to read, performs the reads and updates the
// map with the results.
//
// It is not thread safe to read or mutate the map while this method is running.
BatchGet(keys map[string]types.BatchGetResult) error
// Set sets the value for the given key.
Set(key []byte, value []byte)
// Delete deletes the value for the given key.
Delete(key []byte)
// BatchSet applies the given updates to the cache.
BatchSet(updates []CacheUpdate) error
}
// CacheUpdate describes a single key-value mutation to apply to the cache.
type CacheUpdate struct {
// The key to update.
Key []byte
// The value to set. If nil, the key will be deleted.
Value []byte
}
// IsDelete returns true if the update is a delete operation.
func (u *CacheUpdate) IsDelete() bool {
return u.Value == nil
}