mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2026-01-04 06:16:36 +08:00
彻底替换掉memorygrid
This commit is contained in:
@@ -2,6 +2,7 @@ package ttlcache
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@@ -26,6 +27,26 @@ func (this *Piece) Add(key uint64, item *Item) () {
|
||||
this.locker.Unlock()
|
||||
}
|
||||
|
||||
func (this *Piece) IncreaseInt64(key uint64, delta int64, expiredAt int64) (result int64) {
|
||||
this.locker.Lock()
|
||||
item, ok := this.m[key]
|
||||
if ok {
|
||||
result := types.Int64(item.Value) + delta
|
||||
item.Value = result
|
||||
item.expiredAt = expiredAt
|
||||
} else {
|
||||
if len(this.m) < this.maxItems {
|
||||
result = delta
|
||||
this.m[key] = &Item{
|
||||
Value: delta,
|
||||
expiredAt: expiredAt,
|
||||
}
|
||||
}
|
||||
}
|
||||
this.locker.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Piece) Delete(key uint64) {
|
||||
this.locker.Lock()
|
||||
delete(this.m, key)
|
||||
@@ -60,3 +81,9 @@ func (this *Piece) GC() {
|
||||
}
|
||||
this.locker.Unlock()
|
||||
}
|
||||
|
||||
func (this *Piece) Destroy() {
|
||||
this.locker.Lock()
|
||||
this.m = nil
|
||||
this.locker.Unlock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user