forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache.go
40 lines (32 loc) · 1.2 KB
/
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
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package cache
// Cacher acts as a best effort key value store. Keys must be comparable, as
// defined by https://golang.org/ref/spec#Comparison_operators.
type Cacher interface {
// Put inserts an element into the cache. If spaced is required, elements will
// be evicted.
Put(key, value interface{})
// Get returns the entry in the cache with the key specified, if no value
// exists, false is returned.
Get(key interface{}) (interface{}, bool)
// Evict removes the specified entry from the cache
Evict(key interface{})
// Flush removes all entries from the cache
Flush()
}
// Evictable allows the object to be notified when it is evicted
type Evictable interface {
// Key must return a comparable value as defined by
// https://golang.org/ref/spec#Comparison_operators.
Key() interface{}
Evict()
}
// Deduplicator acts as a best effort deduplication service
type Deduplicator interface {
// Deduplicate returns either the provided value, or a previously provided
// value with the same ID that hasn't yet been evicted
Deduplicate(Evictable) Evictable
// Flush removes all entries from the cache
Flush()
}