/
cache.go
47 lines (38 loc) · 896 Bytes
/
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
41
42
43
44
45
46
47
package cp
import (
"time"
. "github.com/creamsensation/cp/internal/cache"
)
type Cache interface {
Exists(key string) bool
Get(key string, data any)
Set(key string, data any, expiration time.Duration)
Destroy(key string)
}
type cache struct {
control *control
client Client
}
func createCache(control *control) Cache {
return &cache{
control: control,
client: CreateClient(
control.context,
control.config.Cache.Adapter,
control.core.memory,
control.core.redis,
),
}
}
func (c cache) Exists(key string) bool {
return c.client.Exists(key)
}
func (c cache) Get(key string, data any) {
c.control.Error().Check(c.client.Get(key, data))
}
func (c cache) Set(key string, data any, expiration time.Duration) {
c.control.Error().Check(c.client.Set(key, data, expiration))
}
func (c cache) Destroy(key string) {
c.control.Error().Check(c.client.Destroy(key))
}