|
|
|
@ -18,6 +18,11 @@ import (
|
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type BaseCacheEvent struct {
|
|
|
|
|
event.UnimplementedEvent
|
|
|
|
|
ac core.AppCache
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type expireIndexTweetsEvent struct {
|
|
|
|
|
event.UnimplementedEvent
|
|
|
|
|
ac core.AppCache
|
|
|
|
@ -70,6 +75,12 @@ type cacheMyFollowIdsEvent struct {
|
|
|
|
|
expire int64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewBaseCacheEvent(ac core.AppCache) *BaseCacheEvent {
|
|
|
|
|
return &BaseCacheEvent{
|
|
|
|
|
ac: ac,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func OnExpireIndexTweetEvent(userId int64) {
|
|
|
|
|
// TODO: 这里暴躁的将所有 最新/热门/关注 的推文列表缓存都过期掉,后续需要更精细话处理
|
|
|
|
|
events.OnEvent(&expireIndexTweetsEvent{
|
|
|
|
@ -144,6 +155,35 @@ func OnCacheMyFollowIdsEvent(urs core.UserRelationService, userId int64, key ...
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e *BaseCacheEvent) ExpireUserInfo(id int64, name string) error {
|
|
|
|
|
keys := make([]string, 0, 2)
|
|
|
|
|
if id >= 0 {
|
|
|
|
|
keys = append(keys, conf.KeyUserInfoById.Get(id))
|
|
|
|
|
}
|
|
|
|
|
if len(name) > 0 {
|
|
|
|
|
keys = append(keys, conf.KeyUserInfoByName.Get(name))
|
|
|
|
|
}
|
|
|
|
|
return e.ac.Delete(keys...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e *BaseCacheEvent) ExpireUserProfile(name string) error {
|
|
|
|
|
if len(name) > 0 {
|
|
|
|
|
return e.ac.Delete(conf.KeyUserProfileByName.Get(name))
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e *BaseCacheEvent) ExpireUserData(id int64, name string) error {
|
|
|
|
|
keys := make([]string, 0, 3)
|
|
|
|
|
if id >= 0 {
|
|
|
|
|
keys = append(keys, conf.KeyUserInfoById.Get(id))
|
|
|
|
|
}
|
|
|
|
|
if len(name) > 0 {
|
|
|
|
|
keys = append(keys, conf.KeyUserInfoByName.Get(name), conf.KeyUserProfileByName.Get(name))
|
|
|
|
|
}
|
|
|
|
|
return e.ac.Delete(keys...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e *expireIndexTweetsEvent) Name() string {
|
|
|
|
|
return "expireIndexTweetsEvent"
|
|
|
|
|
}
|
|
|
|
|