mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-07 18:50:27 +08:00
如果缓存条件支持206 Partial Content,则第一次加载时自动尝试从分片缓存中读取内容
This commit is contained in:
@@ -236,6 +236,11 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) {
|
|||||||
if reader == nil {
|
if reader == nil {
|
||||||
reader, err = storage.OpenReader(key, useStale, false)
|
reader, err = storage.OpenReader(key, useStale, false)
|
||||||
if err != nil && this.cacheRef.AllowPartialContent {
|
if err != nil && this.cacheRef.AllowPartialContent {
|
||||||
|
// 尝试读取分片的缓存内容
|
||||||
|
if len(rangeHeader) == 0 {
|
||||||
|
// 默认读取开头
|
||||||
|
rangeHeader = "bytes=0-"
|
||||||
|
}
|
||||||
pReader, ranges := this.tryPartialReader(storage, key, useStale, rangeHeader)
|
pReader, ranges := this.tryPartialReader(storage, key, useStale, rangeHeader)
|
||||||
if pReader != nil {
|
if pReader != nil {
|
||||||
isPartialCache = true
|
isPartialCache = true
|
||||||
|
|||||||
@@ -312,9 +312,10 @@ func (this *HTTPWriter) PrepareCache(resp *http.Response, size int64) {
|
|||||||
|
|
||||||
if !caches.CanIgnoreErr(err) {
|
if !caches.CanIgnoreErr(err) {
|
||||||
remotelogs.Error("HTTP_WRITER", "write cache failed: "+err.Error())
|
remotelogs.Error("HTTP_WRITER", "write cache failed: "+err.Error())
|
||||||
|
this.Header().Set("X-Cache", "BYPASS, write cache failed")
|
||||||
|
} else {
|
||||||
|
this.Header().Set("X-Cache", "BYPASS, "+err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Header().Set("X-Cache", "BYPASS, too many requests")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.cacheWriter = cacheWriter
|
this.cacheWriter = cacheWriter
|
||||||
|
|||||||
Reference in New Issue
Block a user