From f8ccb74e7ad8aa6a4aee8bd9132fbd478980fb57 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Thu, 21 Sep 2023 11:51:56 +0800 Subject: [PATCH] add cache expire to user relation cache info --- internal/conf/config.yaml | 1 + internal/conf/setting.go | 1 + internal/dao/cache/events.go | 8 ++++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/conf/config.yaml b/internal/conf/config.yaml index 7c53f4aa..041c9876 100644 --- a/internal/conf/config.yaml +++ b/internal/conf/config.yaml @@ -13,6 +13,7 @@ Cache: IndexTweetsExpire: 120 # 获取广场推文列表过期时间,单位秒, 默认120s OnlineUserExpire: 300 # 标记在线用户 过期时间,单位秒, 默认300s UserInfoExpire: 300 # 获取用户信息过期时间,单位秒, 默认300s + UserRelationExpire: 600 # 用户关系信息过期时间,单位秒, 默认600s EventManager: # 事件管理器的配置参数 MinWorker: 64 # 最小后台工作者, 设置范围[5, ++], 默认64 MaxEventBuf: 128 # 最大log缓存条数, 设置范围[10, ++], 默认128 diff --git a/internal/conf/setting.go b/internal/conf/setting.go index 51ad246c..4cd46237 100644 --- a/internal/conf/setting.go +++ b/internal/conf/setting.go @@ -104,6 +104,7 @@ type cacheConf struct { IndexTweetsExpire int64 OnlineUserExpire int64 UserInfoExpire int64 + UserRelationExpire int64 } type eventManagerConf struct { diff --git a/internal/dao/cache/events.go b/internal/dao/cache/events.go index bd6c1b10..7467e849 100644 --- a/internal/dao/cache/events.go +++ b/internal/dao/cache/events.go @@ -51,6 +51,7 @@ type cacheMyFriendIdsEvent struct { ac core.AppCache urs core.UserRelationService userIds []int64 + expire int64 } type cacheMyFollowIdsEvent struct { @@ -59,6 +60,7 @@ type cacheMyFollowIdsEvent struct { urs core.UserRelationService userId int64 key string + expire int64 } func OnExpireIndexTweetEvent(userId int64) { @@ -106,6 +108,7 @@ func OnCacheMyFriendIdsEvent(urs core.UserRelationService, userIds ...int64) { userIds: userIds, urs: urs, ac: _appCache, + expire: conf.CacheSetting.UserRelationExpire, }) } @@ -121,6 +124,7 @@ func OnCacheMyFollowIdsEvent(urs core.UserRelationService, userId int64, key ... urs: urs, key: cacheKey, ac: _appCache, + expire: conf.CacheSetting.UserRelationExpire, }) } @@ -188,7 +192,7 @@ func (e *cacheMyFriendIdsEvent) Action() error { if err != nil { return err } - e.ac.Set(conf.KeyMyFriendIds.Get(userId), data, 0) + e.ac.Set(conf.KeyMyFriendIds.Get(userId), data, e.expire) } return nil } @@ -211,6 +215,6 @@ func (e *cacheMyFollowIdsEvent) Action() (err error) { if err != nil { return err } - e.ac.Set(e.key, data, 0) + e.ac.Set(e.key, data, e.expire) return nil }