Files
EdgeCommon/pkg/serverconfigs/http_cache_config.go

52 lines
1.6 KiB
Go
Raw Normal View History

2020-10-04 20:38:03 +08:00
package serverconfigs
2021-10-17 20:22:01 +08:00
import (
"encoding/json"
"github.com/iwind/TeaGo/rands"
)
2020-12-18 21:19:25 +08:00
2020-10-04 20:38:03 +08:00
type HTTPCacheConfig struct {
IsPrior bool `yaml:"isPrior" json:"isPrior"`
IsOn bool `yaml:"isOn" json:"isOn"`
AddStatusHeader bool `yaml:"addStatusHeader" json:"addStatusHeader"` // 是否增加命中状态HeaderX-Cache
AddAgeHeader bool `yaml:"addAgeHeader" json:"addAgeHeader"` // 是否增加Age Header
EnableCacheControlMaxAge bool `yaml:"enableCacheControlMaxAge" json:"enableCacheControlMaxAge"` // 是否支持Cache-Control: max-age=...
2022-07-20 18:14:57 +08:00
DisablePolicyRefs bool `yaml:"disablePolicyRefs" json:"disablePolicyRefs"` // 是否停用策略中定义的条件
Key *HTTPCacheKeyConfig `yaml:"key" json:"key"` // 键值全局配置
PurgeIsOn bool `yaml:"purgeIsOn" json:"purgeIsOn"` // 是否允许使用Purge方法清理
PurgeKey string `yaml:"purgeKey" json:"purgeKey"` // Purge时使用的X-Edge-Purge-Key
2021-05-12 16:10:17 +08:00
2021-12-16 17:28:02 +08:00
Stale *HTTPCacheStaleConfig `yaml:"stale" json:"stale"` // 陈旧缓存使用策略
CacheRefs []*HTTPCacheRef `yaml:"cacheRefs" json:"cacheRefs"` // 缓存条件配置
2020-10-04 20:38:03 +08:00
}
func (this *HTTPCacheConfig) Init() error {
for _, cacheRef := range this.CacheRefs {
err := cacheRef.Init()
if err != nil {
return err
}
}
2021-10-17 20:22:01 +08:00
if this.Key != nil {
err := this.Key.Init()
if err != nil {
return err
}
}
2021-10-17 20:22:01 +08:00
if this.PurgeIsOn && len(this.PurgeKey) == 0 {
this.PurgeKey = rands.HexString(32)
}
2020-10-04 20:38:03 +08:00
return nil
}
2020-12-18 21:19:25 +08:00
func (this *HTTPCacheConfig) AsJSON() ([]byte, error) {
return json.Marshal(this)
}