From 5790b41a0358bf36b6abced115ece757ae188f09 Mon Sep 17 00:00:00 2001 From: wood chen Date: Mon, 2 Jun 2025 07:54:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=85=8D=E7=BD=AE=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=B8=85?= =?UTF-8?q?=E7=90=86=E7=BC=93=E5=AD=98=E5=8A=9F=E8=83=BD=E4=BB=A5=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E4=BD=BF=E7=94=A8=E6=96=B0=E9=85=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E4=BB=A3=E7=90=86=E5=A4=84=E7=90=86=E5=99=A8?= =?UTF-8?q?=E7=9A=84=E6=80=A7=E8=83=BD=E5=92=8C=E5=87=86=E7=A1=AE=E6=80=A7?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/handler/proxy.go | 11 +++++++++++ internal/utils/utils.go | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) 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) + } +}