feat: msg local cache

This commit is contained in:
withchao
2024-01-08 16:47:39 +08:00
parent 1ae523dcc2
commit 3d77c1c8cf
6 changed files with 63 additions and 26 deletions
+10 -15
View File
@@ -15,21 +15,12 @@ func New[V any](opts ...Option) Cache[V] {
for _, o := range opts {
o(opt)
}
if opt.enable {
lc := local.NewCache[V](opt.localSlotNum, opt.localSlotSize, opt.localSuccessTTL, opt.localFailedTTL, opt.target)
c := &cache[V]{
opt: opt,
local: lc,
}
go func() {
c.opt.delCh(c.del)
}()
return c
} else {
return &cache[V]{
opt: opt,
}
}
c := &cache[V]{opt: opt}
c.local = local.NewCache[V](opt.localSlotNum, opt.localSlotSize, opt.localSuccessTTL, opt.localFailedTTL, opt.target, c.onEvict)
go func() {
c.opt.delCh(c.del)
}()
return c
}
type cache[V any] struct {
@@ -37,6 +28,10 @@ type cache[V any] struct {
local local.Cache[V]
}
func (c *cache[V]) onEvict(key string, value V) {
}
func (c *cache[V]) del(key ...string) {
for _, k := range key {
c.local.Del(k)