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

Method Purge

internal/caches/storage_memory.go:282–328  ·  view source on GitHub ↗

Purge 批量删除缓存

(keys []string, urlType string)

Source from the content-addressed store, hash-verified

280
281// Purge 批量删除缓存
282func (this *MemoryStorage) Purge(keys []string, urlType string) error {
283 // 目录
284 if urlType == "dir" {
285 for _, key := range keys {
286 // 检查是否有通配符 http(s)://*.example.com
287 var schemeIndex = strings.Index(key, "://")
288 if schemeIndex > 0 {
289 var keyRight = key[schemeIndex+3:]
290 if strings.HasPrefix(keyRight, "*.") {
291 err := this.list.CleanMatchPrefix(key)
292 if err != nil {
293 return err
294 }
295 continue
296 }
297 }
298
299 err := this.list.CleanPrefix(key)
300 if err != nil {
301 return err
302 }
303 }
304 return nil
305 }
306
307 // URL
308 for _, key := range keys {
309 // 检查是否有通配符 http(s)://*.example.com
310 var schemeIndex = strings.Index(key, "://")
311 if schemeIndex > 0 {
312 var keyRight = key[schemeIndex+3:]
313 if strings.HasPrefix(keyRight, "*.") {
314 err := this.list.CleanMatchKey(key)
315 if err != nil {
316 return err
317 }
318 continue
319 }
320 }
321
322 err := this.Delete(key)
323 if err != nil {
324 return err
325 }
326 }
327 return nil
328}
329
330// Stop 停止缓存策略
331func (this *MemoryStorage) Stop() {

Callers 1

TestMemoryStorage_PurgeFunction · 0.95

Calls 4

DeleteMethod · 0.95
CleanMatchPrefixMethod · 0.65
CleanPrefixMethod · 0.65
CleanMatchKeyMethod · 0.65

Tested by 1

TestMemoryStorage_PurgeFunction · 0.76