From 91d67ad384375173d1d383c7f191a94d96e383cc Mon Sep 17 00:00:00 2001 From: xfy Date: Wed, 22 Apr 2026 13:34:51 +0800 Subject: [PATCH] =?UTF-8?q?refactor(cache,config):=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=B8=85=E7=90=86=E5=92=8C=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - disk_cache: 忽略 filepath.Walk 和 Delete 返回值 - tiered_cache: 忽略 l1.Delete 返回值,删除未使用的 revalidate 函数 - config: 简化 multiplier 变量声明 Co-Authored-By: Claude Opus 4.7 --- internal/cache/disk_cache.go | 4 ++-- internal/cache/tiered_cache.go | 14 +------------- internal/config/config.go | 2 +- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/internal/cache/disk_cache.go b/internal/cache/disk_cache.go index 380b6b4..0f6c2ab 100644 --- a/internal/cache/disk_cache.go +++ b/internal/cache/disk_cache.go @@ -134,7 +134,7 @@ func (dc *DiskCache) lazyLoad() { defer close(dc.loadCh) // 扫描目录加载元数据(不加载实际数据) - filepath.Walk(dc.basePath, func(path string, info os.FileInfo, err error) error { + _ = filepath.Walk(dc.basePath, func(path string, info os.FileInfo, err error) error { if err != nil || info.IsDir() { return nil } @@ -214,7 +214,7 @@ func (dc *DiskCache) Get(hashKey uint64, origKey string) (*ProxyCacheEntry, bool if meta.CRC32 != 0 { if crc32.ChecksumIEEE(data) != meta.CRC32 { // 数据损坏,删除条目 - dc.Delete(hashKey) + _ = dc.Delete(hashKey) dc.missCount.Add(1) return nil, false, false } diff --git a/internal/cache/tiered_cache.go b/internal/cache/tiered_cache.go index cdb6d99..ee2cfa2 100644 --- a/internal/cache/tiered_cache.go +++ b/internal/cache/tiered_cache.go @@ -134,7 +134,7 @@ func (tc *TieredCache) Set(hashKey uint64, origKey string, data []byte, headers // Delete 删除缓存条目(实现 CacheBackend 接口)。 func (tc *TieredCache) Delete(hashKey uint64) error { - tc.l1.Delete(hashKey) + _ = tc.l1.Delete(hashKey) return tc.l2.Delete(hashKey) } @@ -238,15 +238,3 @@ func (tc *TieredCache) checkAndPromote() { } } } - -// revalidate 重新验证过期缓存。 -func (tc *TieredCache) revalidate(hashKey uint64, origKey string, entry *ProxyCacheEntry) { - // 标记为正在更新 - entry.Updating.Store(true) - - // 删除 L1 中的过期条目(如果存在) - tc.l1.Delete(hashKey) - - // 注意:实际的重新验证逻辑需要在 proxy 层实现 - // 这里只是标记和清理,真正的重新获取由 proxy 层触发 -} diff --git a/internal/config/config.go b/internal/config/config.go index f56ed75..10977ff 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -455,7 +455,7 @@ func parseSize(s string) (int, error) { // 提取单位 unit := strings.ToLower(s[len(s)-1:]) - var multiplier int = 1 + multiplier := 1 numStr := s if unit == "k" {