mirror of
https://github.com/woodchen-ink/proxy-go.git
synced 2025-07-19 08:51:55 +08:00
优化配置更新逻辑,添加清理缓存功能以确保使用新配置,增强代理处理器的性能和准确性。
This commit is contained in:
parent
83c544bd5b
commit
5790b41a03
@ -191,6 +191,17 @@ func NewProxyHandler(cfg *config.Config) *ProxyHandler {
|
|||||||
handler.pathMap = newCfg.MAP
|
handler.pathMap = newCfg.MAP
|
||||||
handler.prefixTree.update(newCfg.MAP) // 更新前缀匹配树
|
handler.prefixTree.update(newCfg.MAP) // 更新前缀匹配树
|
||||||
handler.config = newCfg
|
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))
|
log.Printf("[Config] 代理处理器配置已更新: %d 个路径映射", len(newCfg.MAP))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -364,3 +364,29 @@ func ParseInt(s string, defaultValue int) int {
|
|||||||
}
|
}
|
||||||
return result
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user