优化代码

This commit is contained in:
GoEdgeLab
2023-03-12 20:32:15 +08:00
parent db3da87251
commit f0ff511576

View File

@@ -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 {