feat: msg local cache

This commit is contained in:
withchao
2024-01-08 15:39:39 +08:00
parent f27b1e43f5
commit d9921248a7
23 changed files with 778 additions and 68 deletions
+38
View File
@@ -0,0 +1,38 @@
package rpccache
import (
"context"
"github.com/openimsdk/open-im-server/v3/pkg/common/cachekey"
"github.com/openimsdk/open-im-server/v3/pkg/common/localcache"
"github.com/openimsdk/open-im-server/v3/pkg/rpcclient"
)
func NewFriendLocalCache(client rpcclient.FriendRpcClient) *FriendLocalCache {
return &FriendLocalCache{
local: localcache.New[any](),
client: client,
}
}
type FriendLocalCache struct {
local localcache.Cache[any]
client rpcclient.FriendRpcClient
}
func (f *FriendLocalCache) GetFriendIDs(ctx context.Context, ownerUserID string) ([]string, error) {
return localcache.AnyValue[[]string](f.local.Get(ctx, cachekey.GetFriendIDsKey(ownerUserID), func(ctx context.Context) (any, error) {
return f.client.GetFriendIDs(ctx, ownerUserID)
}))
}
func (f *FriendLocalCache) IsFriend(ctx context.Context, possibleFriendUserID, userID string) (bool, error) {
return localcache.AnyValue[bool](f.local.Get(ctx, cachekey.GetIsFriendKey(possibleFriendUserID, userID), func(ctx context.Context) (any, error) {
return f.client.IsFriend(ctx, possibleFriendUserID, userID)
}))
}
func (f *FriendLocalCache) IsBlocked(ctx context.Context, possibleBlackUserID, userID string) (bool, error) {
return localcache.AnyValue[bool](f.local.Get(ctx, cachekey.GetIsBlackIDsKey(possibleBlackUserID, userID), func(ctx context.Context) (any, error) {
return f.client.IsFriend(ctx, possibleBlackUserID, userID)
}))
}