mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-27 12:08:52 +08:00
feat: local cache
This commit is contained in:
parent
1db6e3b389
commit
656bfef069
@ -2,6 +2,7 @@ package rpccache
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/OpenIMSDK/tools/log"
|
||||||
"github.com/openimsdk/localcache"
|
"github.com/openimsdk/localcache"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/cachekey"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/cachekey"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
@ -27,8 +28,17 @@ type ConversationLocalCache struct {
|
|||||||
local localcache.Cache[any]
|
local localcache.Cache[any]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConversationLocalCache) GetConversationIDs(ctx context.Context, ownerUserID string) ([]string, error) {
|
func (c *ConversationLocalCache) GetConversationIDs(ctx context.Context, ownerUserID string) (val []string, err error) {
|
||||||
|
log.ZDebug(ctx, "ConversationLocalCache GetConversationIDs req", "ownerUserID", ownerUserID)
|
||||||
|
defer func() {
|
||||||
|
if err == nil {
|
||||||
|
log.ZDebug(ctx, "ConversationLocalCache GetConversationIDs return", "value", val)
|
||||||
|
} else {
|
||||||
|
log.ZError(ctx, "ConversationLocalCache GetConversationIDs return", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
return localcache.AnyValue[[]string](c.local.Get(ctx, cachekey.GetConversationIDsKey(ownerUserID), func(ctx context.Context) (any, error) {
|
return localcache.AnyValue[[]string](c.local.Get(ctx, cachekey.GetConversationIDsKey(ownerUserID), func(ctx context.Context) (any, error) {
|
||||||
|
log.ZDebug(ctx, "ConversationLocalCache GetConversationIDs rpc", "ownerUserID", ownerUserID)
|
||||||
return c.client.GetConversationIDs(ctx, ownerUserID)
|
return c.client.GetConversationIDs(ctx, ownerUserID)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package rpccache
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/OpenIMSDK/tools/log"
|
||||||
"github.com/openimsdk/localcache"
|
"github.com/openimsdk/localcache"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/cachekey"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/cachekey"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||||
@ -46,8 +47,17 @@ func newListMap[V comparable](values []V, err error) (*listMap[V], error) {
|
|||||||
return lm, nil
|
return lm, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupLocalCache) getGroupMemberIDs(ctx context.Context, groupID string) (*listMap[string], error) {
|
func (g *GroupLocalCache) getGroupMemberIDs(ctx context.Context, groupID string) (val *listMap[string], err error) {
|
||||||
|
log.ZDebug(ctx, "GroupLocalCache getGroupMemberIDs req", "groupID", groupID)
|
||||||
|
defer func() {
|
||||||
|
if err == nil {
|
||||||
|
log.ZDebug(ctx, "GroupLocalCache getGroupMemberIDs return", "value", val.List)
|
||||||
|
} else {
|
||||||
|
log.ZError(ctx, "GroupLocalCache getGroupMemberIDs return", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
return localcache.AnyValue[*listMap[string]](g.local.Get(ctx, cachekey.GetGroupMemberIDsKey(groupID), func(ctx context.Context) (any, error) {
|
return localcache.AnyValue[*listMap[string]](g.local.Get(ctx, cachekey.GetGroupMemberIDsKey(groupID), func(ctx context.Context) (any, error) {
|
||||||
|
log.ZDebug(ctx, "GroupLocalCache getGroupMemberIDs rpc", "groupID", groupID)
|
||||||
return newListMap(g.client.GetGroupMemberIDs(ctx, groupID))
|
return newListMap(g.client.GetGroupMemberIDs(ctx, groupID))
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user