节点可以单独设置缓存目录

This commit is contained in:
GoEdgeLab
2022-03-16 15:24:56 +08:00
parent 0a6f136c68
commit d5d823028a
7 changed files with 308 additions and 249 deletions

View File

@@ -80,3 +80,35 @@ func (this *HTTPCachePolicy) IsSame(anotherPolicy *HTTPCachePolicy) bool {
}
return bytes.Equal(policyJSON1, policyJSON2)
}
// UpdateDiskDir 修改文件路径
func (this *HTTPCachePolicy) UpdateDiskDir(dir string) {
if this.Type == CachePolicyStorageFile {
oldOptionsJSON, err := json.Marshal(this.Options)
if err != nil {
return
}
var options = &HTTPFileCacheStorage{}
err = json.Unmarshal(oldOptionsJSON, options)
if err != nil {
return
}
if options.Dir != dir {
options.Dir = dir
newOptionsJSON, err := json.Marshal(options)
if err != nil {
return
}
var newOptionsMap = map[string]interface{}{}
err = json.Unmarshal(newOptionsJSON, &newOptionsMap)
if err != nil {
return
}
this.Options = newOptionsMap
}
}
}