实现缓存策略的部分功能

This commit is contained in:
GoEdgeLab
2020-10-05 16:54:21 +08:00
parent 1f11037d45
commit fcd9e4de06
5 changed files with 114 additions and 25 deletions

View File

@@ -17,8 +17,12 @@ type HTTPCachePolicy struct {
MaxSize *shared.SizeCapacity `yaml:"maxSize" json:"maxSize"` // 单个缓存最大尺寸 TODO 需要实现
Type CachePolicyStorageType `yaml:"type" json:"type"` // 类型
Options map[string]interface{} `yaml:"options" json:"options"` // 选项
Life *shared.TimeDuration `yaml:"life" json:"life"` // 默认有效期 TODO 需要实现
MinLife *shared.TimeDuration `yaml:"minLife" json:"minLife"` // 最小有效期 TODO 需要实现
MaxLife *shared.TimeDuration `yaml:"maxLife" json:"maxLife"` // 最大有效期 TODO 需要实现
capacity int64
maxSize int64
}
// 校验
@@ -29,6 +33,10 @@ func (this *HTTPCachePolicy) Init() error {
this.capacity = this.Capacity.Bytes()
}
if this.maxSize > 0 {
this.maxSize = this.MaxSize.Bytes()
}
return err
}
@@ -37,6 +45,11 @@ func (this *HTTPCachePolicy) CapacitySize() int64 {
return this.capacity
}
// 单个缓存最大尺寸
func (this *HTTPCachePolicy) MaxSizeBytes() int64 {
return this.maxSize
}
// 对比Policy是否有变化
func (this *HTTPCachePolicy) IsSame(anotherPolicy *HTTPCachePolicy) bool {
policyJSON1, err := json.Marshal(this)