计算CC的时候不再跨时间范围累积

This commit is contained in:
刘祥超
2022-05-12 21:48:33 +08:00
parent 84a5d38b0b
commit 45620dcdb7
7 changed files with 13 additions and 11 deletions

View File

@@ -39,13 +39,15 @@ func (this *Piece) Add(key uint64, item *Item) (ok bool) {
return true
}
func (this *Piece) IncreaseInt64(key uint64, delta int64, expiredAt int64) (result int64) {
func (this *Piece) IncreaseInt64(key uint64, delta int64, expiredAt int64, extend bool) (result int64) {
this.locker.Lock()
item, ok := this.m[key]
if ok && item.expiredAt > time.Now().Unix() {
result = types.Int64(item.Value) + delta
item.Value = result
item.expiredAt = expiredAt
if extend {
item.expiredAt = expiredAt
}
this.expiresList.Add(key, expiredAt)
} else {
if len(this.m) < this.maxItems {