diff --git a/internal/handler/proxy.go b/internal/handler/proxy.go index 78be286..10f5750 100644 --- a/internal/handler/proxy.go +++ b/internal/handler/proxy.go @@ -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)) }) diff --git a/internal/utils/utils.go b/internal/utils/utils.go index dbf64f2..4d7b193 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -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) + } +}