From 83bde18e88942cbde9fbacb948466a753fe92440 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Fri, 17 Dec 2021 11:53:59 +0800 Subject: [PATCH] =?UTF-8?q?X-Cache=E5=A2=9E=E5=8A=A0STALE=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request_cache.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/nodes/http_request_cache.go b/internal/nodes/http_request_cache.go index b470ad0..715efe1 100644 --- a/internal/nodes/http_request_cache.go +++ b/internal/nodes/http_request_cache.go @@ -19,7 +19,7 @@ import ( // 读取缓存 func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) { this.cacheCanTryStale = false - + cachePolicy := this.Server.HTTPCachePolicy if cachePolicy == nil || !cachePolicy.IsOn { return @@ -185,8 +185,13 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) { _ = reader.Close() }() - this.varMapping["cache.status"] = "HIT" - this.logAttrs["cache.status"] = "HIT" + if useStale { + this.varMapping["cache.status"] = "STALE" + this.logAttrs["cache.status"] = "STALE" + } else { + this.varMapping["cache.status"] = "HIT" + this.logAttrs["cache.status"] = "HIT" + } // 准备Buffer buf := bytePool32k.Get() @@ -227,7 +232,11 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) { this.varMapping["cache.age"] = age if addStatusHeader { - this.writer.Header().Set("X-Cache", "HIT, "+refType+", "+reader.TypeName()) + if useStale { + this.writer.Header().Set("X-Cache", "STALE, "+refType+", "+reader.TypeName()) + } else { + this.writer.Header().Set("X-Cache", "HIT, "+refType+", "+reader.TypeName()) + } } if this.web.Cache.AddAgeHeader { this.writer.Header().Set("Age", age)