mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-09 03:50:27 +08:00
缓存增加UPDATING状态
This commit is contained in:
@@ -566,6 +566,7 @@ func (this *HTTPWriter) prepareCache(size int64) {
|
|||||||
|
|
||||||
// 不支持Range
|
// 不支持Range
|
||||||
if len(this.Header().Get("Content-Range")) > 0 {
|
if len(this.Header().Get("Content-Range")) > 0 {
|
||||||
|
this.req.varMapping["cache.status"] = "BYPASS"
|
||||||
if addStatusHeader {
|
if addStatusHeader {
|
||||||
this.Header().Set("X-Cache", "BYPASS, not supported Content-Range")
|
this.Header().Set("X-Cache", "BYPASS, not supported Content-Range")
|
||||||
}
|
}
|
||||||
@@ -574,6 +575,7 @@ func (this *HTTPWriter) prepareCache(size int64) {
|
|||||||
|
|
||||||
// 如果允许 ChunkedEncoding,就无需尺寸的判断,因为此时的 size 为 -1
|
// 如果允许 ChunkedEncoding,就无需尺寸的判断,因为此时的 size 为 -1
|
||||||
if !cacheRef.AllowChunkedEncoding && size < 0 {
|
if !cacheRef.AllowChunkedEncoding && size < 0 {
|
||||||
|
this.req.varMapping["cache.status"] = "BYPASS"
|
||||||
if addStatusHeader {
|
if addStatusHeader {
|
||||||
this.Header().Set("X-Cache", "BYPASS, ChunkedEncoding")
|
this.Header().Set("X-Cache", "BYPASS, ChunkedEncoding")
|
||||||
}
|
}
|
||||||
@@ -581,6 +583,7 @@ func (this *HTTPWriter) prepareCache(size int64) {
|
|||||||
}
|
}
|
||||||
if size >= 0 && ((cacheRef.MaxSizeBytes() > 0 && size > cacheRef.MaxSizeBytes()) ||
|
if size >= 0 && ((cacheRef.MaxSizeBytes() > 0 && size > cacheRef.MaxSizeBytes()) ||
|
||||||
(cachePolicy.MaxSizeBytes() > 0 && size > cachePolicy.MaxSizeBytes()) || (cacheRef.MinSizeBytes() > size)) {
|
(cachePolicy.MaxSizeBytes() > 0 && size > cachePolicy.MaxSizeBytes()) || (cacheRef.MinSizeBytes() > size)) {
|
||||||
|
this.req.varMapping["cache.status"] = "BYPASS"
|
||||||
if addStatusHeader {
|
if addStatusHeader {
|
||||||
this.Header().Set("X-Cache", "BYPASS, Content-Length")
|
this.Header().Set("X-Cache", "BYPASS, Content-Length")
|
||||||
}
|
}
|
||||||
@@ -589,6 +592,7 @@ func (this *HTTPWriter) prepareCache(size int64) {
|
|||||||
|
|
||||||
// 检查状态
|
// 检查状态
|
||||||
if len(cacheRef.Status) > 0 && !lists.ContainsInt(cacheRef.Status, this.StatusCode()) {
|
if len(cacheRef.Status) > 0 && !lists.ContainsInt(cacheRef.Status, this.StatusCode()) {
|
||||||
|
this.req.varMapping["cache.status"] = "BYPASS"
|
||||||
if addStatusHeader {
|
if addStatusHeader {
|
||||||
this.Header().Set("X-Cache", "BYPASS, Status: "+types.String(this.StatusCode()))
|
this.Header().Set("X-Cache", "BYPASS, Status: "+types.String(this.StatusCode()))
|
||||||
}
|
}
|
||||||
@@ -602,6 +606,7 @@ func (this *HTTPWriter) prepareCache(size int64) {
|
|||||||
values := strings.Split(cacheControl, ",")
|
values := strings.Split(cacheControl, ",")
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
if cacheRef.ContainsCacheControl(strings.TrimSpace(value)) {
|
if cacheRef.ContainsCacheControl(strings.TrimSpace(value)) {
|
||||||
|
this.req.varMapping["cache.status"] = "BYPASS"
|
||||||
if addStatusHeader {
|
if addStatusHeader {
|
||||||
this.Header().Set("X-Cache", "BYPASS, Cache-Control: "+cacheControl)
|
this.Header().Set("X-Cache", "BYPASS, Cache-Control: "+cacheControl)
|
||||||
}
|
}
|
||||||
@@ -613,6 +618,7 @@ func (this *HTTPWriter) prepareCache(size int64) {
|
|||||||
|
|
||||||
// Set-Cookie
|
// Set-Cookie
|
||||||
if cacheRef.SkipResponseSetCookie && len(this.writer.Header().Get("Set-Cookie")) > 0 {
|
if cacheRef.SkipResponseSetCookie && len(this.writer.Header().Get("Set-Cookie")) > 0 {
|
||||||
|
this.req.varMapping["cache.status"] = "BYPASS"
|
||||||
if addStatusHeader {
|
if addStatusHeader {
|
||||||
this.Header().Set("X-Cache", "BYPASS, Set-Cookie")
|
this.Header().Set("X-Cache", "BYPASS, Set-Cookie")
|
||||||
}
|
}
|
||||||
@@ -621,6 +627,7 @@ func (this *HTTPWriter) prepareCache(size int64) {
|
|||||||
|
|
||||||
// 校验其他条件
|
// 校验其他条件
|
||||||
if cacheRef.Conds != nil && cacheRef.Conds.HasResponseConds() && !cacheRef.Conds.MatchResponse(this.req.Format) {
|
if cacheRef.Conds != nil && cacheRef.Conds.HasResponseConds() && !cacheRef.Conds.MatchResponse(this.req.Format) {
|
||||||
|
this.req.varMapping["cache.status"] = "BYPASS"
|
||||||
if addStatusHeader {
|
if addStatusHeader {
|
||||||
this.Header().Set("X-Cache", "BYPASS, ResponseConds")
|
this.Header().Set("X-Cache", "BYPASS, ResponseConds")
|
||||||
}
|
}
|
||||||
@@ -630,12 +637,18 @@ func (this *HTTPWriter) prepareCache(size int64) {
|
|||||||
// 打开缓存写入
|
// 打开缓存写入
|
||||||
storage := caches.SharedManager.FindStorageWithPolicy(cachePolicy.Id)
|
storage := caches.SharedManager.FindStorageWithPolicy(cachePolicy.Id)
|
||||||
if storage == nil {
|
if storage == nil {
|
||||||
|
this.req.varMapping["cache.status"] = "BYPASS"
|
||||||
if addStatusHeader {
|
if addStatusHeader {
|
||||||
this.Header().Set("X-Cache", "BYPASS, Storage")
|
this.Header().Set("X-Cache", "BYPASS, Storage")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.req.varMapping["cache.status"] = "UPDATING"
|
||||||
|
if addStatusHeader {
|
||||||
|
this.Header().Set("X-Cache", "UPDATING")
|
||||||
|
}
|
||||||
|
|
||||||
this.cacheStorage = storage
|
this.cacheStorage = storage
|
||||||
life := cacheRef.LifeSeconds()
|
life := cacheRef.LifeSeconds()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user