From 59cca9c6c712c2b699bbdbf09ee69478b4a203a4 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 1 Oct 2023 20:30:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E4=BB=B6=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=BC=93=E5=AD=98=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/list_file.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/caches/list_file.go b/internal/caches/list_file.go index c5d454b..97f929d 100644 --- a/internal/caches/list_file.go +++ b/internal/caches/list_file.go @@ -9,6 +9,7 @@ import ( "github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/ttlcache" "github.com/TeaOSLab/EdgeNode/internal/utils/dbs" + "github.com/TeaOSLab/EdgeNode/internal/utils/fasttime" "github.com/TeaOSLab/EdgeNode/internal/utils/fnv" "github.com/iwind/TeaGo/types" "os" @@ -102,7 +103,7 @@ func (this *FileList) Add(hash string, item *Item) error { // 这里不增加点击量,以减少对数据库的操作次数 - this.memoryCache.Write(hash, 1, item.ExpiredAt) + this.memoryCache.Write(hash, 1, this.maxExpiresAtForMemoryCache(item.ExpiredAt)) if this.onAdd != nil { this.onAdd(item) @@ -140,7 +141,7 @@ func (this *FileList) Exist(hash string) (bool, error) { } return false, err } - this.memoryCache.Write(hash, 1, expiredAt) + this.memoryCache.Write(hash, 1, this.maxExpiresAtForMemoryCache(expiredAt)) return true, nil } @@ -523,3 +524,11 @@ func (this *FileList) UpgradeV3(oldDir string, brokenOnError bool) error { return nil } + +func (this *FileList) maxExpiresAtForMemoryCache(expiresAt int64) int64 { + var maxTimestamp = fasttime.Now().Unix() + 86400*7 + if expiresAt > maxTimestamp { + return maxTimestamp + } + return expiresAt +}