MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / UpdatePolicy

Method UpdatePolicy

internal/caches/storage_file.go:166–230  ·  view source on GitHub ↗

UpdatePolicy 修改策略

(newPolicy *serverconfigs.HTTPCachePolicy)

Source from the content-addressed store, hash-verified

164
165// UpdatePolicy 修改策略
166func (this *FileStorage) UpdatePolicy(newPolicy *serverconfigs.HTTPCachePolicy) {
167 var oldOpenFileCache = this.options.OpenFileCache
168
169 this.policy = newPolicy
170
171 newOptionsJSON, err := json.Marshal(newPolicy.Options)
172 if err != nil {
173 return
174 }
175 var newOptions = serverconfigs.NewHTTPFileCacheStorage()
176 err = json.Unmarshal(newOptionsJSON, newOptions)
177 if err != nil {
178 remotelogs.Error("CACHE", "update policy '"+types.String(this.policy.Id)+"' failed: decode options failed: "+err.Error())
179 return
180 }
181
182 var subDirs = []*FileDir{}
183 for _, subDir := range newOptions.SubDirs {
184 subDirs = append(subDirs, &FileDir{
185 Path: subDir.Path,
186 Capacity: subDir.Capacity,
187 IsFull: false,
188 })
189 }
190 this.subDirs = subDirs
191 this.checkDiskSpace()
192
193 err = newOptions.Init()
194 if err != nil {
195 remotelogs.Error("CACHE", "update policy '"+types.String(this.policy.Id)+"' failed: init options failed: "+err.Error())
196 return
197 }
198
199 this.options = newOptions
200
201 var memoryStorage = this.memoryStorage
202 if memoryStorage != nil {
203 if newOptions.MemoryPolicy != nil && newOptions.MemoryPolicy.CapacityBytes() > 0 {
204 memoryStorage.UpdatePolicy(newOptions.MemoryPolicy)
205 } else {
206 memoryStorage.Stop()
207 this.memoryStorage = nil
208 }
209 } else if newOptions.MemoryPolicy != nil && this.options.MemoryPolicy.Capacity != nil && this.options.MemoryPolicy.Capacity.Count > 0 {
210 err = this.createMemoryStorage()
211 if err != nil {
212 remotelogs.Error("CACHE", "update policy '"+types.String(this.policy.Id)+"' failed: create memory storage failed: "+err.Error())
213 }
214 }
215
216 // open cache
217 oldOpenFileCacheJSON, _ := json.Marshal(oldOpenFileCache)
218 newOpenFileCacheJSON, _ := json.Marshal(this.options.OpenFileCache)
219 if !bytes.Equal(oldOpenFileCacheJSON, newOpenFileCacheJSON) {
220 this.initOpenFileCache()
221 }
222
223 // Purge Ticker

Callers

nothing calls this directly

Calls 11

checkDiskSpaceMethod · 0.95
createMemoryStorageMethod · 0.95
initOpenFileCacheMethod · 0.95
initPurgeTickerMethod · 0.95
ErrorFunction · 0.92
InitMethod · 0.65
UpdatePolicyMethod · 0.65
StopMethod · 0.65
ResetMethod · 0.65
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected