mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-01 07:35:58 +08:00
feat: msg local cache
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user