mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
feat: msg rpc local cache
This commit is contained in:
parent
e26a582836
commit
899f1f15a4
@ -528,23 +528,38 @@ prometheus:
|
|||||||
thirdPrometheusPort: [ ${THIRD_PROM_PORT} ]
|
thirdPrometheusPort: [ ${THIRD_PROM_PORT} ]
|
||||||
messageTransferPrometheusPort: [ ${MSG_TRANSFER_PROM_PORT} ] # List of ports
|
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:
|
localCache:
|
||||||
user:
|
user:
|
||||||
topic: delete_cache_user
|
topic: DELETE_CACHE_USER
|
||||||
slotNum: 500
|
slotNum: 500
|
||||||
slotSize: 20000
|
slotSize: 20000
|
||||||
|
successExpire: 300
|
||||||
|
failedExpire: 5
|
||||||
|
|
||||||
group:
|
group:
|
||||||
topic: delete_cache_group
|
topic: DELETE_CACHE_GROUP
|
||||||
slotNum: 500
|
slotNum: 500
|
||||||
slotSize: 20000
|
slotSize: 20000
|
||||||
|
successExpire: 300
|
||||||
|
failedExpire: 5
|
||||||
|
|
||||||
friend:
|
friend:
|
||||||
topic: delete_cache_friend
|
topic: DELETE_CACHE_FRIEND
|
||||||
slotNum: 500
|
slotNum: 500
|
||||||
slotSize: 20000
|
slotSize: 20000
|
||||||
|
successExpire: 300
|
||||||
|
failedExpire: 5
|
||||||
|
|
||||||
conversation:
|
conversation:
|
||||||
topic: delete_cache_conversation
|
topic: DELETE_CACHE_CONVERSATION
|
||||||
slotNum: 500
|
slotNum: 500
|
||||||
slotSize: 20000
|
slotSize: 20000
|
||||||
|
successExpire: 300
|
||||||
|
failedExpire: 5
|
@ -16,6 +16,7 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/tools/discoveryregistry"
|
"github.com/OpenIMSDK/tools/discoveryregistry"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
@ -373,9 +374,19 @@ type notification struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type LocalCache struct {
|
type LocalCache struct {
|
||||||
Topic string `yaml:"topic"`
|
Topic string `yaml:"topic"`
|
||||||
SlotNum int `yaml:"slotNum"`
|
SlotNum int `yaml:"slotNum"`
|
||||||
SlotSize int `yaml:"slotSize"`
|
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 {
|
func (l LocalCache) Enable() bool {
|
||||||
|
@ -20,6 +20,9 @@ func NewConversationLocalCache(client rpcclient.ConversationRpcClient, cli redis
|
|||||||
local: localcache.New[any](
|
local: localcache.New[any](
|
||||||
localcache.WithLocalSlotNum(lc.SlotNum),
|
localcache.WithLocalSlotNum(lc.SlotNum),
|
||||||
localcache.WithLocalSlotSize(lc.SlotSize),
|
localcache.WithLocalSlotSize(lc.SlotSize),
|
||||||
|
localcache.WithLinkSlotNum(lc.SlotNum),
|
||||||
|
localcache.WithLocalSuccessTTL(lc.Success()),
|
||||||
|
localcache.WithLocalFailedTTL(lc.Failed()),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
if lc.Enable() {
|
if lc.Enable() {
|
||||||
|
@ -18,6 +18,9 @@ func NewFriendLocalCache(client rpcclient.FriendRpcClient, cli redis.UniversalCl
|
|||||||
local: localcache.New[any](
|
local: localcache.New[any](
|
||||||
localcache.WithLocalSlotNum(lc.SlotNum),
|
localcache.WithLocalSlotNum(lc.SlotNum),
|
||||||
localcache.WithLocalSlotSize(lc.SlotSize),
|
localcache.WithLocalSlotSize(lc.SlotSize),
|
||||||
|
localcache.WithLinkSlotNum(lc.SlotNum),
|
||||||
|
localcache.WithLocalSuccessTTL(lc.Success()),
|
||||||
|
localcache.WithLocalFailedTTL(lc.Failed()),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
if lc.Enable() {
|
if lc.Enable() {
|
||||||
|
@ -20,6 +20,9 @@ func NewGroupLocalCache(client rpcclient.GroupRpcClient, cli redis.UniversalClie
|
|||||||
local: localcache.New[any](
|
local: localcache.New[any](
|
||||||
localcache.WithLocalSlotNum(lc.SlotNum),
|
localcache.WithLocalSlotNum(lc.SlotNum),
|
||||||
localcache.WithLocalSlotSize(lc.SlotSize),
|
localcache.WithLocalSlotSize(lc.SlotSize),
|
||||||
|
localcache.WithLinkSlotNum(lc.SlotNum),
|
||||||
|
localcache.WithLocalSuccessTTL(lc.Success()),
|
||||||
|
localcache.WithLocalFailedTTL(lc.Failed()),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
if lc.Enable() {
|
if lc.Enable() {
|
||||||
|
@ -20,6 +20,9 @@ func NewUserLocalCache(client rpcclient.UserRpcClient, cli redis.UniversalClient
|
|||||||
local: localcache.New[any](
|
local: localcache.New[any](
|
||||||
localcache.WithLocalSlotNum(lc.SlotNum),
|
localcache.WithLocalSlotNum(lc.SlotNum),
|
||||||
localcache.WithLocalSlotSize(lc.SlotSize),
|
localcache.WithLocalSlotSize(lc.SlotSize),
|
||||||
|
localcache.WithLinkSlotNum(lc.SlotNum),
|
||||||
|
localcache.WithLocalSuccessTTL(lc.Success()),
|
||||||
|
localcache.WithLocalFailedTTL(lc.Failed()),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
if lc.Enable() {
|
if lc.Enable() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user