fix(s3): 解决缓存清理时的类型断言错误

- 添加类型检查避免非 cacheItem 类型值导致的 panic
- 跳过 lock_xxx 对应的 *sync.Mutex 类型值
- 保持原有缓存过期清理逻辑不变
This commit is contained in:
2025-12-29 10:49:42 +08:00
parent b23794587f
commit 86f0182593
2 changed files with 6 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import (
"ZhenTuLocalPassiveAdapter/logger"
"context"
"fmt"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
)

View File

@@ -203,7 +203,11 @@ func init() {
func cleanupCache() {
var keysToDelete []interface{}
s3Cache.Range(func(key, value interface{}) bool {
item := value.(cacheItem)
// 类型检查:跳过非 cacheItem 类型的值(例如 lock_xxx 对应的 *sync.Mutex)
item, ok := value.(cacheItem)
if !ok {
return true
}
if time.Now().After(item.expires) {
keysToDelete = append(keysToDelete, key)
}