Files
EdgeCommon/pkg/serverconfigs/http_cache_policy.go

52 lines
1.6 KiB
Go
Raw Normal View History

2020-09-13 19:27:47 +08:00
package serverconfigs
import (
2020-10-04 16:10:19 +08:00
"bytes"
"encoding/json"
2020-09-13 19:27:47 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
)
// 缓存策略配置
2020-09-16 09:09:31 +08:00
type HTTPCachePolicy struct {
2020-10-02 17:22:46 +08:00
Id int64 `yaml:"id" json:"id"`
IsOn bool `yaml:"isOn" json:"isOn"` // 是否开启
Name string `yaml:"name" json:"name"` // 名称
Description string `yaml:"description" json:"description"` // 描述
2020-10-04 16:10:19 +08:00
Capacity *shared.SizeCapacity `yaml:"capacity" json:"capacity"` // 最大内容容量 TODO 需要实现
MaxKeys int64 `yaml:"maxKeys" json:"maxKeys"` // 最多Key值 TODO 需要实现
MaxSize *shared.SizeCapacity `yaml:"maxSize" json:"maxSize"` // 单个缓存最大尺寸 TODO 需要实现
2020-10-04 20:38:03 +08:00
Type CachePolicyStorageType `yaml:"type" json:"type"` // 类型
2020-10-02 17:22:46 +08:00
Options map[string]interface{} `yaml:"options" json:"options"` // 选项
2020-09-13 19:27:47 +08:00
capacity int64
}
// 校验
2020-09-20 11:56:22 +08:00
func (this *HTTPCachePolicy) Init() error {
2020-09-13 19:27:47 +08:00
var err error
2020-10-02 17:22:46 +08:00
if this.Capacity != nil {
this.capacity = this.Capacity.Bytes()
2020-09-13 19:27:47 +08:00
}
return err
}
// 容量
2020-09-16 09:09:31 +08:00
func (this *HTTPCachePolicy) CapacitySize() int64 {
2020-09-13 19:27:47 +08:00
return this.capacity
}
2020-10-04 16:10:19 +08:00
// 对比Policy是否有变化
func (this *HTTPCachePolicy) IsSame(anotherPolicy *HTTPCachePolicy) bool {
policyJSON1, err := json.Marshal(this)
if err != nil {
return false
}
policyJSON2, err := json.Marshal(anotherPolicy)
if err != nil {
return false
}
return bytes.Equal(policyJSON1, policyJSON2)
}