可以在缓存条件里设置Expires Header

This commit is contained in:
刘祥超
2021-12-08 17:40:27 +08:00
parent 00e46c6e3d
commit 252b8af422
3 changed files with 27 additions and 7 deletions

View File

@@ -13,12 +13,13 @@ type HTTPCacheRef struct {
IsOn bool `yaml:"isOn" json:"isOn"`
CachePolicyId int64 `yaml:"cachePolicyId" json:"cachePolicyId"`
Key string `yaml:"key" json:"key"` // 每个缓存的Key规则里面可以有变量
Life *shared.TimeDuration `yaml:"life" json:"life"` // 时间
Status []int `yaml:"status" json:"status"` // 缓存的状态码列表
MinSize *shared.SizeCapacity `yaml:"minSize" json:"minSize"` // 能够缓存的最小尺寸
MaxSize *shared.SizeCapacity `yaml:"maxSize" json:"maxSize"` // 能够缓存的最尺寸
Methods []string `yaml:"methods" json:"methods"` // 支持的请求方法
Key string `yaml:"key" json:"key"` // 每个缓存的Key规则里面可以有变量
Life *shared.TimeDuration `yaml:"life" json:"life"` // 时间
ExpiresTime *HTTPExpiresTimeConfig `yaml:"expiresTime" json:"expiresTime"` // 客户端过期时间
Status []int `yaml:"status" json:"status"` // 缓存的状态码列表
MinSize *shared.SizeCapacity `yaml:"minSize" json:"minSize"` // 能够缓存的最尺寸
MaxSize *shared.SizeCapacity `yaml:"maxSize" json:"maxSize"` // 能够缓存的最大尺寸
Methods []string `yaml:"methods" json:"methods"` // 支持的请求方法
SkipResponseCacheControlValues []string `yaml:"skipCacheControlValues" json:"skipCacheControlValues"` // 可以跳过的响应的Cache-Control值
SkipResponseSetCookie bool `yaml:"skipSetCookie" json:"skipSetCookie"` // 是否跳过响应的Set-Cookie Header

View File

@@ -0,0 +1,16 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package serverconfigs
import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
)
// HTTPExpiresTimeConfig 发送到客户端的过期时间设置
type HTTPExpiresTimeConfig struct {
IsPrior bool `yaml:"isPrior" json:"isPrior"` // 是否覆盖父级设置
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
Overwrite bool `yaml:"overwrite" json:"overwrite"` // 是否覆盖
AutoCalculate bool `yaml:"autoCalculate" json:"autoCalculate"` // 是否自动计算
Duration *shared.TimeDuration `yaml:"duration" json:"duration"` // 周期
}

View File

@@ -13,9 +13,10 @@ const (
TimeDurationUnitMinute TimeDurationUnit = "minute"
TimeDurationUnitHour TimeDurationUnit = "hour"
TimeDurationUnitDay TimeDurationUnit = "day"
TimeDurationUnitWeek TimeDurationUnit = "week"
)
// 时间间隔
// TimeDuration 时间间隔
type TimeDuration struct {
Count int64 `yaml:"count" json:"count"` // 数量
Unit TimeDurationUnit `yaml:"unit" json:"unit"` // 单位
@@ -33,6 +34,8 @@ func (this *TimeDuration) Duration() time.Duration {
return time.Duration(this.Count) * time.Hour
case TimeDurationUnitDay:
return time.Duration(this.Count) * 24 * time.Hour
case TimeDurationUnitWeek:
return time.Duration(this.Count) * 24 * 7 * time.Hour
default:
return time.Duration(this.Count) * time.Second
}