-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharccache.go
More file actions
39 lines (31 loc) · 862 Bytes
/
arccache.go
File metadata and controls
39 lines (31 loc) · 862 Bytes
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 lrucache
import (
"time"
"github.com/easy-cache/cache"
"github.com/hashicorp/golang-lru"
)
type arcCacheDriver struct {
arccache *lru.ARCCache
}
func (acd arcCacheDriver) Get(key string) ([]byte, bool, error) {
item, hit := acd.arccache.Get(key)
if hit == false {
return nil, false, nil
}
bs, ok := item.(*cache.Item).GetValue()
return bs, ok, nil
}
func (acd arcCacheDriver) Set(key string, val []byte, ttl time.Duration) error {
acd.arccache.Add(key, cache.NewItem(val, ttl))
return nil
}
func (acd arcCacheDriver) Del(key string) error {
acd.arccache.Remove(key)
return nil
}
func NewARCDriver(arccache *lru.ARCCache) cache.DriverInterface {
return arcCacheDriver{arccache: arccache}
}
func NewARCCache(arccache *lru.ARCCache, args ...interface{}) cache.Interface {
return cache.New(append(args, NewARCDriver(arccache))...)
}