diff --git a/deployments/templates/openim.yaml b/deployments/templates/openim.yaml index b7548ffce..8e7e05904 100644 --- a/deployments/templates/openim.yaml +++ b/deployments/templates/openim.yaml @@ -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 \ No newline at end of file + slotSize: 20000 + successExpire: 300 + failedExpire: 5 \ No newline at end of file diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index 3cc1f4e6e..20eea0464 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -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 { diff --git a/pkg/rpccache/conversation.go b/pkg/rpccache/conversation.go index 061b05bec..8eadad9d4 100644 --- a/pkg/rpccache/conversation.go +++ b/pkg/rpccache/conversation.go @@ -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() { diff --git a/pkg/rpccache/friend.go b/pkg/rpccache/friend.go index d9ee377b3..66694f618 100644 --- a/pkg/rpccache/friend.go +++ b/pkg/rpccache/friend.go @@ -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() { diff --git a/pkg/rpccache/group.go b/pkg/rpccache/group.go index 6a12aa9f0..b3c666da4 100644 --- a/pkg/rpccache/group.go +++ b/pkg/rpccache/group.go @@ -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() { diff --git a/pkg/rpccache/user.go b/pkg/rpccache/user.go index fd4c24c75..7d6cd5c7e 100644 --- a/pkg/rpccache/user.go +++ b/pkg/rpccache/user.go @@ -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() {