mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-11 21:00:25 +08:00
X-Cache增加STALE状态
This commit is contained in:
@@ -19,7 +19,7 @@ import (
|
|||||||
// 读取缓存
|
// 读取缓存
|
||||||
func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) {
|
func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) {
|
||||||
this.cacheCanTryStale = false
|
this.cacheCanTryStale = false
|
||||||
|
|
||||||
cachePolicy := this.Server.HTTPCachePolicy
|
cachePolicy := this.Server.HTTPCachePolicy
|
||||||
if cachePolicy == nil || !cachePolicy.IsOn {
|
if cachePolicy == nil || !cachePolicy.IsOn {
|
||||||
return
|
return
|
||||||
@@ -185,8 +185,13 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) {
|
|||||||
_ = reader.Close()
|
_ = reader.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
this.varMapping["cache.status"] = "HIT"
|
if useStale {
|
||||||
this.logAttrs["cache.status"] = "HIT"
|
this.varMapping["cache.status"] = "STALE"
|
||||||
|
this.logAttrs["cache.status"] = "STALE"
|
||||||
|
} else {
|
||||||
|
this.varMapping["cache.status"] = "HIT"
|
||||||
|
this.logAttrs["cache.status"] = "HIT"
|
||||||
|
}
|
||||||
|
|
||||||
// 准备Buffer
|
// 准备Buffer
|
||||||
buf := bytePool32k.Get()
|
buf := bytePool32k.Get()
|
||||||
@@ -227,7 +232,11 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) {
|
|||||||
this.varMapping["cache.age"] = age
|
this.varMapping["cache.age"] = age
|
||||||
|
|
||||||
if addStatusHeader {
|
if addStatusHeader {
|
||||||
this.writer.Header().Set("X-Cache", "HIT, "+refType+", "+reader.TypeName())
|
if useStale {
|
||||||
|
this.writer.Header().Set("X-Cache", "STALE, "+refType+", "+reader.TypeName())
|
||||||
|
} else {
|
||||||
|
this.writer.Header().Set("X-Cache", "HIT, "+refType+", "+reader.TypeName())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if this.web.Cache.AddAgeHeader {
|
if this.web.Cache.AddAgeHeader {
|
||||||
this.writer.Header().Set("Age", age)
|
this.writer.Header().Set("Age", age)
|
||||||
|
|||||||
Reference in New Issue
Block a user