From c039691a71d92ee8f28a4d37781976c6a484e863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Wed, 13 Dec 2023 18:41:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E8=AE=BE=E7=BD=AE=E4=B8=AD?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E8=AE=BE=E7=BD=AE=E7=BC=93=E5=AD=98=E4=B8=BB?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=EF=BC=8C=E7=94=A8=E6=9D=A5=E5=A4=8D=E7=94=A8?= =?UTF-8?q?=E5=A4=9A=E5=9F=9F=E5=90=8D=E4=B8=8B=E7=9A=84=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request_cache.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/internal/nodes/http_request_cache.go b/internal/nodes/http_request_cache.go index 1abcf78..a1357fd 100644 --- a/internal/nodes/http_request_cache.go +++ b/internal/nodes/http_request_cache.go @@ -3,6 +3,7 @@ package nodes import ( "bytes" "errors" + "github.com/TeaOSLab/EdgeCommon/pkg/configutils" "github.com/TeaOSLab/EdgeNode/internal/caches" "github.com/TeaOSLab/EdgeNode/internal/compressions" "github.com/TeaOSLab/EdgeNode/internal/remotelogs" @@ -130,7 +131,22 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) { var tags = []string{} // 检查是否有缓存 - var key = this.Format(this.cacheRef.Key) + var key string + if this.web.Cache.Key != nil && this.web.Cache.Key.IsOn && len(this.web.Cache.Key.Host) > 0 { + key = configutils.ParseVariables(this.cacheRef.Key, func(varName string) (value string) { + switch varName { + case "scheme": + return this.web.Cache.Key.Scheme + case "host": + return this.web.Cache.Key.Host + default: + return this.Format("${" + varName + "}") + } + }) + } else { + key = this.Format(this.cacheRef.Key) + } + if len(key) == 0 { this.cacheRef = nil cacheBypassDescription = "BYPASS, empty key"