-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
69 lines (65 loc) · 2.69 KB
/
interface.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
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
package storage
// Cacher provides caching services
type Cacher interface {
// Clear is used to completely clear the cache.
Clear()
// Put adds a value to the cache. Returns true if an eviction occurred.
Put(key []byte, value interface{}, sizeInBytes int) (evicted bool)
// Get looks up a key's value from the cache.
Get(key []byte) (value interface{}, ok bool)
// Has checks if a key is in the cache, without updating the
// recent-ness or deleting it for being stale.
Has(key []byte) bool
// Peek returns the key value (or undefined if not found) without updating
// the "recently used"-ness of the key.
Peek(key []byte) (value interface{}, ok bool)
// HasOrAdd checks if a key is in the cache without updating the
// recent-ness or deleting it for being stale, and if not adds the value.
HasOrAdd(key []byte, value interface{}, sizeInBytes int) (has, added bool)
// Remove removes the provided key from the cache.
Remove(key []byte)
// Keys returns a slice of the keys in the cache, from oldest to newest.
Keys() [][]byte
// Len returns the number of items in the cache.
Len() int
// SizeInBytesContained returns the size in bytes of all contained elements
SizeInBytesContained() uint64
// MaxSize returns the maximum number of items which can be stored in the cache.
MaxSize() int
// RegisterHandler registers a new handler to be called when a new data is added
RegisterHandler(handler func(key []byte, value interface{}), id string)
// UnRegisterHandler deletes the handler from the list
UnRegisterHandler(id string)
// Close closes the underlying temporary db if the cacher implementation has one,
// otherwise it does nothing
Close() error
// IsInterfaceNil returns true if there is no value under the interface
IsInterfaceNil() bool
}
// ForEachItem is an iterator callback
type ForEachItem func(key []byte, value interface{})
// LRUCacheHandler is the interface for LRU cache.
type LRUCacheHandler interface {
Add(key, value interface{}) bool
Get(key interface{}) (value interface{}, ok bool)
Contains(key interface{}) (ok bool)
ContainsOrAdd(key, value interface{}) (ok, evicted bool)
Peek(key interface{}) (value interface{}, ok bool)
Remove(key interface{}) bool
Keys() []interface{}
Len() int
Purge()
}
// SizedLRUCacheHandler is the interface for size capable LRU cache.
type SizedLRUCacheHandler interface {
AddSized(key, value interface{}, sizeInBytes int64) bool
Get(key interface{}) (value interface{}, ok bool)
Contains(key interface{}) (ok bool)
AddSizedIfMissing(key, value interface{}, sizeInBytes int64) (ok, evicted bool)
Peek(key interface{}) (value interface{}, ok bool)
Remove(key interface{}) bool
Keys() []interface{}
Len() int
SizeInBytesContained() uint64
Purge()
}