mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-08 03:26:36 +08:00
feat: local cache
This commit is contained in:
parent
6e1f96a720
commit
d26a1b2090
20
pkg/rpccache/common.go
Normal file
20
pkg/rpccache/common.go
Normal file
@ -0,0 +1,20 @@
|
||||
package rpccache
|
||||
|
||||
func newListMap[V comparable](values []V, err error) (*listMap[V], error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lm := &listMap[V]{
|
||||
List: values,
|
||||
Map: make(map[V]struct{}, len(values)),
|
||||
}
|
||||
for _, value := range values {
|
||||
lm.Map[value] = struct{}{}
|
||||
}
|
||||
return lm, nil
|
||||
}
|
||||
|
||||
type listMap[V comparable] struct {
|
||||
List []V
|
||||
Map map[V]struct{}
|
||||
}
|
@ -19,7 +19,9 @@ func NewConversationLocalCache(client rpcclient.ConversationRpcClient, cli redis
|
||||
localcache.WithLocalSlotSize(lc.SlotSize),
|
||||
),
|
||||
}
|
||||
go subscriberRedisDeleteCache(context.Background(), cli, lc.Topic, x.local.DelLocal)
|
||||
if lc.Enable() {
|
||||
go subscriberRedisDeleteCache(context.Background(), cli, lc.Topic, x.local.DelLocal)
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,9 @@ func NewFriendLocalCache(client rpcclient.FriendRpcClient, cli redis.UniversalCl
|
||||
localcache.WithLocalSlotSize(lc.SlotSize),
|
||||
),
|
||||
}
|
||||
go subscriberRedisDeleteCache(context.Background(), cli, lc.Topic, x.local.DelLocal)
|
||||
if lc.Enable() {
|
||||
go subscriberRedisDeleteCache(context.Background(), cli, lc.Topic, x.local.DelLocal)
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,9 @@ func NewGroupLocalCache(client rpcclient.GroupRpcClient, cli redis.UniversalClie
|
||||
localcache.WithLocalSlotSize(lc.SlotSize),
|
||||
),
|
||||
}
|
||||
go subscriberRedisDeleteCache(context.Background(), cli, lc.Topic, x.local.DelLocal)
|
||||
if lc.Enable() {
|
||||
go subscriberRedisDeleteCache(context.Background(), cli, lc.Topic, x.local.DelLocal)
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
@ -28,25 +30,6 @@ type GroupLocalCache struct {
|
||||
local localcache.Cache[any]
|
||||
}
|
||||
|
||||
type listMap[V comparable] struct {
|
||||
List []V
|
||||
Map map[V]struct{}
|
||||
}
|
||||
|
||||
func newListMap[V comparable](values []V, err error) (*listMap[V], error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lm := &listMap[V]{
|
||||
List: values,
|
||||
Map: make(map[V]struct{}, len(values)),
|
||||
}
|
||||
for _, value := range values {
|
||||
lm.Map[value] = struct{}{}
|
||||
}
|
||||
return lm, nil
|
||||
}
|
||||
|
||||
func (g *GroupLocalCache) getGroupMemberIDs(ctx context.Context, groupID string) (val *listMap[string], err error) {
|
||||
log.ZDebug(ctx, "GroupLocalCache getGroupMemberIDs req", "groupID", groupID)
|
||||
defer func() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user