From f0762fe1b912202a61a68f40f721639ede9e2a05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Fri, 29 Sep 2023 14:52:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=E7=BC=93=E5=AD=98=E6=97=B6?= =?UTF-8?q?=E6=99=BA=E8=83=BD=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E5=AE=8C=E6=95=B4LFU?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/storage_file.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/caches/storage_file.go b/internal/caches/storage_file.go index df26750..55eb780 100644 --- a/internal/caches/storage_file.go +++ b/internal/caches/storage_file.go @@ -1001,6 +1001,7 @@ func (this *FileStorage) purgeLoop() { // 计算是否应该开启LFU清理 var capacityBytes = this.diskCapacityBytes() var startLFU = false + var requireFullLFU = false // 是否需要完整执行LFU var lfuFreePercent = this.policy.PersistenceLFUFreePercent if lfuFreePercent <= 0 { lfuFreePercent = 5 @@ -1066,6 +1067,7 @@ func (this *FileStorage) purgeLoop() { purgeCount = 2000 } } + for i := 0; i < times; i++ { countFound, err := this.list.Purge(purgeCount, func(hash string) error { path, _ := this.hashPath(hash) @@ -1082,6 +1084,10 @@ func (this *FileStorage) purgeLoop() { } if countFound < purgeCount { + if i == 0 && startLFU { + requireFullLFU = true + } + break } @@ -1119,7 +1125,11 @@ func (this *FileStorage) purgeLoop() { count = maxCount } - remotelogs.Println("CACHE", "LFU purge policy '"+this.policy.Name+"' id: "+types.String(this.policy.Id)+", count: "+types.String(count)) + var prefix = "" + if requireFullLFU { + prefix = "fully " + } + remotelogs.Println("CACHE", prefix+"LFU purge policy '"+this.policy.Name+"' id: "+types.String(this.policy.Id)+", count: "+types.String(count)) err := this.list.PurgeLFU(count, func(hash string) error { path, _ := this.hashPath(hash) err := this.removeCacheFile(path) @@ -1134,7 +1144,7 @@ func (this *FileStorage) purgeLoop() { } // 检查硬盘空间状态 - if !this.hasFullDisk() { + if !requireFullLFU && !this.hasFullDisk() { break } }