-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypes.go
39 lines (31 loc) · 921 Bytes
/
types.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
package cache
import (
"context"
"time"
)
type Provider[T, V any] interface {
Get(ctx context.Context, key *Key[V], requiredModelVersion uint16) (*T, error)
MGet(ctx context.Context, keys []*Key[V], requiredModelVersion uint16) (map[*Key[V]]*T, []*Key[V], error)
MSet(ctx context.Context, values map[string]*T, ttl time.Duration) error
}
type Builder[T, V any] struct {
providers []Provider[T, V]
ttl time.Duration
modelVersion uint16
}
type Cache[T any, V any] struct {
builder *Builder[T, V]
}
type Key[V any] struct {
Key string
OriginalValue V
}
type GetFromSourceFn[T, V any] func(ctx context.Context, key []*Key[V]) (map[*Key[V]]*T, error)
type GetSingleFromSourceFn[T, V any] func(ctx context.Context, key *Key[V]) (*T, error)
type Entity interface {
GetCacheModelVersion() uint16
}
type missingData[T, V any] struct {
provider Provider[T, V]
missingKeys []*Key[V]
}