feat(channel): enhance channel service with caching and repository updates
- Updated ChannelService to include caching for channel lists, improving performance and reducing database load. - Introduced cache invalidation methods to ensure channel list consistency after modifications. - Modified ChannelRepository to remove unused ListByIDs method, streamlining the repository interface. - Updated wire generation to inject cache into ChannelService for enhanced functionality. - Added new cache key constants for channel-related data management.
This commit is contained in:
13
internal/cache/keys.go
vendored
13
internal/cache/keys.go
vendored
@@ -31,6 +31,9 @@ const (
|
||||
PrefixUserInfo = "users:info"
|
||||
PrefixUserMe = "users:me"
|
||||
|
||||
// 频道相关(全量列表一条缓存,供 /channels、帖子 channel 填充共用)
|
||||
PrefixChannelsAllList = "channels:all_list"
|
||||
|
||||
// 消息缓存相关
|
||||
keyPrefixMsgHash = "msg_hash" // 消息详情 Hash
|
||||
keyPrefixMsgIndex = "msg_index" // 消息索引 Sorted Set
|
||||
@@ -116,6 +119,16 @@ func UserMeKey(userID string) string {
|
||||
return fmt.Sprintf("%s:%s", PrefixUserMe, userID)
|
||||
}
|
||||
|
||||
// ChannelsAllListKey 频道全量列表缓存键(含未启用,供 MapByIDs 解析历史帖子 channel)
|
||||
func ChannelsAllListKey() string {
|
||||
return PrefixChannelsAllList
|
||||
}
|
||||
|
||||
// InvalidateChannelList 失效频道列表缓存(管理端增删改频道后调用)
|
||||
func InvalidateChannelList(c Cache) {
|
||||
c.Delete(ChannelsAllListKey())
|
||||
}
|
||||
|
||||
// InvalidatePostList 失效帖子列表缓存
|
||||
func InvalidatePostList(cache Cache) {
|
||||
cache.DeleteByPrefix(PrefixPostList)
|
||||
|
||||
Reference in New Issue
Block a user