如果缓存条件支持206 Partial Content,则第一次加载时自动尝试从分片缓存中读取内容

This commit is contained in:
刘祥超
2022-06-18 19:31:10 +08:00
parent 4c4033bb56
commit b1d0c8852e
2 changed files with 8 additions and 2 deletions

View File

@@ -236,6 +236,11 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) {
if reader == nil {
reader, err = storage.OpenReader(key, useStale, false)
if err != nil && this.cacheRef.AllowPartialContent {
// 尝试读取分片的缓存内容
if len(rangeHeader) == 0 {
// 默认读取开头
rangeHeader = "bytes=0-"
}
pReader, ranges := this.tryPartialReader(storage, key, useStale, rangeHeader)
if pReader != nil {
isPartialCache = true