optimize cache logic for get unread message count

pull/385/head
Michael Li 1 year ago
parent 657d99a725
commit 8ee4ff7e8d
No known key found for this signature in database

@ -111,4 +111,5 @@ type WebCache interface {
GetUnreadMsgCountResp(uid int64) ([]byte, error)
PutUnreadMsgCountResp(uid int64, data []byte) error
DelUnreadMsgCountResp(uid int64) error
ExistUnreadMsgCountResp(uid int64) bool
}

@ -98,6 +98,10 @@ func (s *webCache) DelUnreadMsgCountResp(uid int64) error {
return s.Delete(conf.KeyUnreadMsg.Get(uid))
}
func (s *webCache) ExistUnreadMsgCountResp(uid int64) bool {
return s.Exist(conf.KeyUnreadMsg.Get(uid))
}
func newAppCache() *appCache {
return &appCache{
cscExpire: conf.CacheSetting.CientSideCacheExpire,

@ -76,6 +76,10 @@ func (p *CacheRespEvent) Name() string {
}
func (p *CacheRespEvent) Action() error {
if p.ac.Exist(p.key) {
// do nothing
return nil
}
resp := &joint.JsonResp{
Code: 0,
Msg: "success",

@ -51,6 +51,10 @@ func (e *cacheUnreadMsgEvent) Name() string {
}
func (e *cacheUnreadMsgEvent) Action() error {
if e.wc.ExistUnreadMsgCountResp(e.uid) {
// do nothing
return nil
}
count, err := e.ds.GetUnreadCount(e.uid)
if err != nil {
return fmt.Errorf("cacheUnreadMsgEvent action occurs error: %w", err)

Loading…
Cancel
Save