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

Method Purge

internal/caches/storage_file.go:875–938  ·  view source on GitHub ↗

Purge 清理过期的缓存

(keys []string, urlType string)

Source from the content-addressed store, hash-verified

873
874// Purge 清理过期的缓存
875func (this *FileStorage) Purge(keys []string, urlType string) error {
876 // 是否正在退出
877 if teaconst.IsQuiting {
878 return nil
879 }
880
881 // 先尝试内存缓存
882 this.runMemoryStorageSafety(func(memoryStorage *MemoryStorage) {
883 _ = memoryStorage.Purge(keys, urlType)
884 })
885
886 // 目录
887 if urlType == "dir" {
888 for _, key := range keys {
889 // 检查是否有通配符 http(s)://*.example.com
890 var schemeIndex = strings.Index(key, "://")
891 if schemeIndex > 0 {
892 var keyRight = key[schemeIndex+3:]
893 if strings.HasPrefix(keyRight, "*.") {
894 err := this.list.CleanMatchPrefix(key)
895 if err != nil {
896 return err
897 }
898 continue
899 }
900 }
901
902 err := this.list.CleanPrefix(key)
903 if err != nil {
904 return err
905 }
906 }
907 return nil
908 }
909
910 // URL
911 for _, key := range keys {
912 // 检查是否有通配符 http(s)://*.example.com
913 var schemeIndex = strings.Index(key, "://")
914 if schemeIndex > 0 {
915 var keyRight = key[schemeIndex+3:]
916 if strings.HasPrefix(keyRight, "*.") {
917 err := this.list.CleanMatchKey(key)
918 if err != nil {
919 return err
920 }
921 continue
922 }
923 }
924
925 // 普通的Key
926 hash, path, _ := this.keyPath(key)
927 err := this.removeCacheFile(path)
928 if err != nil && !os.IsNotExist(err) {
929 return err
930 }
931
932 err = this.list.Remove(hash)

Callers

nothing calls this directly

Calls 8

keyPathMethod · 0.95
removeCacheFileMethod · 0.95
PurgeMethod · 0.65
CleanMatchPrefixMethod · 0.65
CleanPrefixMethod · 0.65
CleanMatchKeyMethod · 0.65
RemoveMethod · 0.65

Tested by

no test coverage detected