优化ttlcache回收速度

This commit is contained in:
GoEdgeLab
2023-10-12 16:03:52 +08:00
parent 36b1f84c20
commit fce75df033
3 changed files with 41 additions and 20 deletions

View File

@@ -105,14 +105,14 @@ func (this *Piece[T]) GC() {
this.lastGCTime = currentTime - 3600
}
var min = this.lastGCTime
var max = currentTime
if min > max {
var minTime = this.lastGCTime
var maxTime = currentTime
if minTime > maxTime {
// 过去的时间比现在大,则从这一秒重新开始
min = max
minTime = maxTime
}
for i := min; i <= max; i++ {
for i := minTime; i <= maxTime; i++ {
var itemMap = this.expiresList.GC(i)
if len(itemMap) > 0 {
this.gcItemMap(itemMap)