根据系统内存自动调节ttlcache的最大条目

This commit is contained in:
刘祥超
2021-10-04 09:12:17 +08:00
parent 1ca967534a
commit 3888565c0f
6 changed files with 55 additions and 4 deletions

View File

@@ -17,7 +17,7 @@ func NewPiece(maxItems int) *Piece {
return &Piece{m: map[uint64]*Item{}, maxItems: maxItems}
}
func (this *Piece) Add(key uint64, item *Item) {
func (this *Piece) Add(key uint64, item *Item) (ok bool) {
this.locker.Lock()
if len(this.m) >= this.maxItems {
this.locker.Unlock()
@@ -25,6 +25,7 @@ func (this *Piece) Add(key uint64, item *Item) {
}
this.m[key] = item
this.locker.Unlock()
return true
}
func (this *Piece) IncreaseInt64(key uint64, delta int64, expiredAt int64) (result int64) {