refactor(cache,config): 代码清理和优化
- disk_cache: 忽略 filepath.Walk 和 Delete 返回值 - tiered_cache: 忽略 l1.Delete 返回值,删除未使用的 revalidate 函数 - config: 简化 multiplier 变量声明 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
92b7040a5f
commit
91d67ad384
4
internal/cache/disk_cache.go
vendored
4
internal/cache/disk_cache.go
vendored
@ -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
|
||||
}
|
||||
|
||||
14
internal/cache/tiered_cache.go
vendored
14
internal/cache/tiered_cache.go
vendored
@ -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 层触发
|
||||
}
|
||||
|
||||
@ -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" {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user