|
|
@ -18,6 +18,11 @@ import (
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type BaseCacheEvent struct {
|
|
|
|
|
|
|
|
event.UnimplementedEvent
|
|
|
|
|
|
|
|
ac core.AppCache
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type expireIndexTweetsEvent struct {
|
|
|
|
type expireIndexTweetsEvent struct {
|
|
|
|
event.UnimplementedEvent
|
|
|
|
event.UnimplementedEvent
|
|
|
|
ac core.AppCache
|
|
|
|
ac core.AppCache
|
|
|
@ -70,6 +75,12 @@ type cacheMyFollowIdsEvent struct {
|
|
|
|
expire int64
|
|
|
|
expire int64
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewBaseCacheEvent(ac core.AppCache) *BaseCacheEvent {
|
|
|
|
|
|
|
|
return &BaseCacheEvent{
|
|
|
|
|
|
|
|
ac: ac,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func OnExpireIndexTweetEvent(userId int64) {
|
|
|
|
func OnExpireIndexTweetEvent(userId int64) {
|
|
|
|
// TODO: 这里暴躁的将所有 最新/热门/关注 的推文列表缓存都过期掉,后续需要更精细话处理
|
|
|
|
// TODO: 这里暴躁的将所有 最新/热门/关注 的推文列表缓存都过期掉,后续需要更精细话处理
|
|
|
|
events.OnEvent(&expireIndexTweetsEvent{
|
|
|
|
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 {
|
|
|
|
func (e *expireIndexTweetsEvent) Name() string {
|
|
|
|
return "expireIndexTweetsEvent"
|
|
|
|
return "expireIndexTweetsEvent"
|
|
|
|
}
|
|
|
|
}
|
|
|
|