-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcacher.go
57 lines (47 loc) · 1.37 KB
/
cacher.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
package gsr
import (
"context"
"io"
"time"
)
// SimpleCacher interface definition
type SimpleCacher interface {
// Closer close cache handle
io.Closer
// Clear all cache data
Clear() error
// Has basic operation
Has(key string) bool
Del(key string) error
Get(key string) any
Set(key string, val any, ttl time.Duration) error
// GetMulti multi operation
GetMulti(keys []string) map[string]any
SetMulti(values map[string]any, ttl time.Duration) error
DelMulti(keys []string) error
}
// ContextCacher interface.
type ContextCacher interface {
SimpleCacher
// WithContext and clone new cacher
WithContext(ctx context.Context) ContextCacher
}
// ContextOpCacher interface.
type ContextOpCacher interface {
SimpleCacher
// HasWithCtx basic operation
HasWithCtx(ctx context.Context, key string) bool
DelWithCtx(ctx context.Context, key string) error
GetWithCtx(ctx context.Context, key string) any
SetWithCtx(ctx context.Context, key string, val any, ttl time.Duration) error
// MGetWithCtx multi keys operation
MGetWithCtx(ctx context.Context, keys []string) map[string]any
MSetWithCtx(ctx context.Context, values map[string]any, ttl time.Duration) error
MDelWithCtx(ctx context.Context, keys []string) error
}
// CodedCacher interface.
type CodedCacher interface {
SimpleCacher
// GetAs get and decode cache value to object ptr
GetAs(key string, ptr any) error
}