generated from bool64/go-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcache.go
More file actions
71 lines (59 loc) · 1.57 KB
/
cache.go
File metadata and controls
71 lines (59 loc) · 1.57 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package cache
import (
"context"
"io"
"time"
)
const (
// DefaultTTL indicates default value (replaced by config.TimeToLive) for entry expiration time.
DefaultTTL = time.Duration(0)
// UnlimitedTTL indicates unlimited TTL for config TimeToLive.
UnlimitedTTL = time.Duration(-1)
)
// Reader reads from cache.
type Reader interface {
// Read returns cached value or error.
Read(ctx context.Context, key []byte) (interface{}, error)
}
// Writer writes to cache.
type Writer interface {
// Write stores value in cache with a given key.
Write(ctx context.Context, key []byte, value interface{}) error
}
// Deleter deletes from cache.
type Deleter interface {
// Delete removes a cache entry with a given key
// and returns ErrNotFound for non-existent keys.
Delete(ctx context.Context, key []byte) error
}
// ReadWriter reads from and writes to cache.
type ReadWriter interface {
Reader
Writer
}
// Entry is cache entry with key and value.
type Entry interface {
Key() []byte
Value() interface{}
ExpireAt() time.Time
}
// Walker calls function for every entry in cache and fails on first error returned by that function.
//
// Count of processed entries is returned.
type Walker interface {
Walk(cb func(entry Entry) error) (int, error)
}
// Dumper dumps cache entries in binary format.
type Dumper interface {
Dump(w io.Writer) (int, error)
}
// Restorer restores cache entries from binary dump.
type Restorer interface {
Restore(r io.Reader) (int, error)
}
// WalkDumpRestorer walks, dumps and restores cache.
type WalkDumpRestorer interface {
Dumper
Walker
Restorer
}