mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2026-02-19 23:35:36 +08:00
实现缓存策略的部分功能
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user