From f0ff511576a2222d096a32edf1083bf13aebb4af Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 12 Mar 2023 20:32:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_writer.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/nodes/http_writer.go b/internal/nodes/http_writer.go index c773c78..37c30f2 100644 --- a/internal/nodes/http_writer.go +++ b/internal/nodes/http_writer.go @@ -332,6 +332,12 @@ func (this *HTTPWriter) PrepareCache(resp *http.Response, size int64) { } } } + + // 先清理以前的 + if this.cacheWriter != nil { + _ = this.cacheWriter.Discard() + } + cacheWriter, err := storage.OpenWriter(cacheKey, expiresAt, this.StatusCode(), this.calculateHeaderLength(), totalSize, cacheRef.MaxSizeBytes(), this.isPartial) if err != nil { if err == caches.ErrEntityTooLarge && addStatusHeader { @@ -346,9 +352,6 @@ func (this *HTTPWriter) PrepareCache(resp *http.Response, size int64) { } return } - if this.cacheWriter != nil { - _ = this.cacheWriter.Discard() - } this.cacheWriter = cacheWriter if this.isPartial {