From afc533c3e4ba4079b6bceaf858ffaf1d85f637a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Tue, 10 Oct 2023 14:02:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86LFU=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=97=B6=E6=97=A5=E5=BF=97=E6=89=93=E5=8D=B0=E6=B6=88=E8=80=97?= =?UTF-8?q?=E6=97=B6=E9=97=B4/=E5=88=A0=E9=99=A4=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E5=88=86=E5=8C=BA=E4=BF=A1=E6=81=AF=E6=96=87=E4=BB=B6=E5=89=8D?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=96=87=E4=BB=B6=E6=98=AF=E5=90=A6=E5=AD=98?= =?UTF-8?q?=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/storage_file.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/internal/caches/storage_file.go b/internal/caches/storage_file.go index 50e697d..0a2046c 100644 --- a/internal/caches/storage_file.go +++ b/internal/caches/storage_file.go @@ -1129,11 +1129,7 @@ func (this *FileStorage) purgeLoop() { count = maxCount } - 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)) + var before = time.Now() err := this.list.PurgeLFU(count, func(hash string) error { path, _ := this.hashPath(hash) fsutils.WriteBegin() @@ -1145,6 +1141,13 @@ func (this *FileStorage) purgeLoop() { return nil }) + + 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)+", cost:"+fmt.Sprintf("%.2fms", time.Since(before).Seconds()*1000)) + if err != nil { remotelogs.Warn("CACHE", "purge file storage in LFU failed: "+err.Error()) } @@ -1399,7 +1402,11 @@ func (this *FileStorage) removeCacheFile(path string) error { if openFileCache != nil { openFileCache.Close(partialPath) } - _ = os.Remove(partialPath) + + _, statErr := os.Stat(partialPath) + if statErr == nil { + _ = os.Remove(partialPath) + } } return err }