mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-06 01:50:26 +08:00
加快ttlcache GC速度
This commit is contained in:
@@ -146,12 +146,20 @@ func (this *Cache) Count() (count int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *Cache) GC() {
|
func (this *Cache) GC() {
|
||||||
this.pieces[this.gcPieceIndex].GC()
|
var index = this.gcPieceIndex
|
||||||
var newIndex = this.gcPieceIndex + 1
|
var maxPiecesPerGC = 4
|
||||||
if newIndex >= int(this.countPieces) {
|
for i := index; i < index+maxPiecesPerGC; i++ {
|
||||||
newIndex = 0
|
if i >= int(this.countPieces) {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
this.gcPieceIndex = newIndex
|
this.pieces[i].GC()
|
||||||
|
}
|
||||||
|
|
||||||
|
index += maxPiecesPerGC
|
||||||
|
if index >= int(this.countPieces) {
|
||||||
|
index = 0
|
||||||
|
}
|
||||||
|
this.gcPieceIndex = index
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Cache) Clean() {
|
func (this *Cache) Clean() {
|
||||||
|
|||||||
Reference in New Issue
Block a user