feat: msg rpc local cache

This commit is contained in:
withchao 2024-01-18 15:06:07 +08:00
parent e26a582836
commit 899f1f15a4
6 changed files with 46 additions and 8 deletions

View File

@ -528,23 +528,38 @@ prometheus:
thirdPrometheusPort: [ ${THIRD_PROM_PORT} ]
messageTransferPrometheusPort: [ ${MSG_TRANSFER_PROM_PORT} ] # List of ports
###################### LocalCache configuration information ######################
# topic: redis subscriber channel
# slotNum: number of slots, multiple slots can prevent too many keys from competing for a lock
# slotSize: number of slots, the number of cached keys per slot, the overall cache quantity is slotNum * slotSize
# successExpire: successful cache time seconds
# failedExpire: failed cache time seconds
# disable local caching and annotate topic, slotNum, and slotSize
localCache:
user:
topic: delete_cache_user
topic: DELETE_CACHE_USER
slotNum: 500
slotSize: 20000
successExpire: 300
failedExpire: 5
group:
topic: delete_cache_group
topic: DELETE_CACHE_GROUP
slotNum: 500
slotSize: 20000
successExpire: 300
failedExpire: 5
friend:
topic: delete_cache_friend
topic: DELETE_CACHE_FRIEND
slotNum: 500
slotSize: 20000
successExpire: 300
failedExpire: 5
conversation:
topic: delete_cache_conversation
topic: DELETE_CACHE_CONVERSATION
slotNum: 500
slotSize: 20000
slotSize: 20000
successExpire: 300
failedExpire: 5

View File

@ -16,6 +16,7 @@ package config
import (
"bytes"
"time"
"github.com/OpenIMSDK/tools/discoveryregistry"
"gopkg.in/yaml.v3"
@ -373,9 +374,19 @@ type notification struct {
}
type LocalCache struct {
Topic string `yaml:"topic"`
SlotNum int `yaml:"slotNum"`
SlotSize int `yaml:"slotSize"`
Topic string `yaml:"topic"`
SlotNum int `yaml:"slotNum"`
SlotSize int `yaml:"slotSize"`
SuccessExpire int `yaml:"successExpire"` // second
FailedExpire int `yaml:"failedExpire"` // second
}
func (l LocalCache) Failed() time.Duration {
return time.Second * time.Duration(l.FailedExpire)
}
func (l LocalCache) Success() time.Duration {
return time.Second * time.Duration(l.SuccessExpire)
}
func (l LocalCache) Enable() bool {

View File

@ -20,6 +20,9 @@ func NewConversationLocalCache(client rpcclient.ConversationRpcClient, cli redis
local: localcache.New[any](
localcache.WithLocalSlotNum(lc.SlotNum),
localcache.WithLocalSlotSize(lc.SlotSize),
localcache.WithLinkSlotNum(lc.SlotNum),
localcache.WithLocalSuccessTTL(lc.Success()),
localcache.WithLocalFailedTTL(lc.Failed()),
),
}
if lc.Enable() {

View File

@ -18,6 +18,9 @@ func NewFriendLocalCache(client rpcclient.FriendRpcClient, cli redis.UniversalCl
local: localcache.New[any](
localcache.WithLocalSlotNum(lc.SlotNum),
localcache.WithLocalSlotSize(lc.SlotSize),
localcache.WithLinkSlotNum(lc.SlotNum),
localcache.WithLocalSuccessTTL(lc.Success()),
localcache.WithLocalFailedTTL(lc.Failed()),
),
}
if lc.Enable() {

View File

@ -20,6 +20,9 @@ func NewGroupLocalCache(client rpcclient.GroupRpcClient, cli redis.UniversalClie
local: localcache.New[any](
localcache.WithLocalSlotNum(lc.SlotNum),
localcache.WithLocalSlotSize(lc.SlotSize),
localcache.WithLinkSlotNum(lc.SlotNum),
localcache.WithLocalSuccessTTL(lc.Success()),
localcache.WithLocalFailedTTL(lc.Failed()),
),
}
if lc.Enable() {

View File

@ -20,6 +20,9 @@ func NewUserLocalCache(client rpcclient.UserRpcClient, cli redis.UniversalClient
local: localcache.New[any](
localcache.WithLocalSlotNum(lc.SlotNum),
localcache.WithLocalSlotSize(lc.SlotSize),
localcache.WithLinkSlotNum(lc.SlotNum),
localcache.WithLocalSuccessTTL(lc.Success()),
localcache.WithLocalFailedTTL(lc.Failed()),
),
}
if lc.Enable() {