优化配置更新逻辑,添加清理缓存功能以确保使用新配置,增强代理处理器的性能和准确性。

This commit is contained in:
wood chen 2025-06-02 07:54:25 +08:00
parent 83c544bd5b
commit 5790b41a03
2 changed files with 37 additions and 0 deletions

View File

@ -191,6 +191,17 @@ func NewProxyHandler(cfg *config.Config) *ProxyHandler {
handler.pathMap = newCfg.MAP
handler.prefixTree.update(newCfg.MAP) // 更新前缀匹配树
handler.config = newCfg
// 清理ExtensionMatcher缓存确保使用新配置
if handler.Cache != nil {
handler.Cache.InvalidateAllExtensionMatchers()
log.Printf("[Config] ExtensionMatcher缓存已清理")
}
// 清理URL可访问性缓存和文件大小缓存
utils.ClearAccessibilityCache()
utils.ClearFileSizeCache()
log.Printf("[Config] 代理处理器配置已更新: %d 个路径映射", len(newCfg.MAP))
})

View File

@ -364,3 +364,29 @@ func ParseInt(s string, defaultValue int) int {
}
return result
}
// ClearAccessibilityCache 清理可访问性缓存
func ClearAccessibilityCache() {
count := 0
accessCache.Range(func(key, value interface{}) bool {
accessCache.Delete(key)
count++
return true
})
if count > 0 {
log.Printf("[AccessibilityCache] 清理了 %d 个可访问性缓存项", count)
}
}
// ClearFileSizeCache 清理文件大小缓存
func ClearFileSizeCache() {
count := 0
sizeCache.Range(func(key, value interface{}) bool {
sizeCache.Delete(key)
count++
return true
})
if count > 0 {
log.Printf("[FileSizeCache] 清理了 %d 个文件大小缓存项", count)
}
}