mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
fix private msg cache.
This commit is contained in:
parent
8d5283edfc
commit
331dd98a7c
@ -49,7 +49,7 @@ func (c *QQClient) c2cMessageSyncProcessor(rsp *msg.GetMessageResponse) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
strKey := fmt.Sprintf("%d%d%d%d", pMsg.Head.GetFromUin(), pMsg.Head.GetToUin(), pMsg.Head.GetMsgSeq(), pMsg.Head.GetMsgUid())
|
strKey := fmt.Sprintf("%d%d%d%d", pMsg.Head.GetFromUin(), pMsg.Head.GetToUin(), pMsg.Head.GetMsgSeq(), pMsg.Head.GetMsgUid())
|
||||||
if _, ok := c.msgSvcCache.Get(strKey); ok {
|
if _, ok := c.msgSvcCache.GetAndUpdate(strKey, time.Minute*5); ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
c.msgSvcCache.Add(strKey, "", time.Minute)
|
c.msgSvcCache.Add(strKey, "", time.Minute)
|
||||||
|
14
utils/ttl.go
14
utils/ttl.go
@ -72,6 +72,20 @@ func (cache *Cache) Get(key string) (interface{}, bool) {
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cache *Cache) GetAndUpdate(key string, ttl time.Duration) (interface{}, bool) {
|
||||||
|
cache.lock.RLock()
|
||||||
|
defer cache.lock.RUnlock()
|
||||||
|
|
||||||
|
e, ok := cache.cache[key]
|
||||||
|
|
||||||
|
if ok && e.expiry != nil {
|
||||||
|
expiry := time.Now().Add(ttl)
|
||||||
|
e.expiry = &expiry
|
||||||
|
return e.value, true
|
||||||
|
}
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
// Add - add key/value in cache
|
// Add - add key/value in cache
|
||||||
func (cache *Cache) Add(key string, value interface{}, ttl time.Duration) {
|
func (cache *Cache) Add(key string, value interface{}, ttl time.Duration) {
|
||||||
cache.lock.Lock()
|
cache.lock.Lock()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user