FilesystemKeyRefs builds refs affected by a write/delete to key. Directory prefixes are included so list fragments for common prefix queries are evicted.
(name, key string)
| 90 | // FilesystemKeyRefs builds refs affected by a write/delete to key. Directory |
| 91 | // prefixes are included so list fragments for common prefix queries are evicted. |
| 92 | func FilesystemKeyRefs(name, key string) []RowRef { |
| 93 | key = normalizeFilesystemCacheID(key) |
| 94 | refs := []RowRef{{ |
| 95 | Source: CacheSourceFS, |
| 96 | Scope: name, |
| 97 | Kind: CacheKindKey, |
| 98 | ID: key, |
| 99 | }} |
| 100 | |
| 101 | seen := map[string]struct{}{} |
| 102 | addPrefix := func(prefix string) { |
| 103 | prefix = normalizeFilesystemCacheID(prefix) |
| 104 | if _, ok := seen[prefix]; ok { |
| 105 | return |
| 106 | } |
| 107 | seen[prefix] = struct{}{} |
| 108 | refs = append(refs, RowRef{ |
| 109 | Source: CacheSourceFS, |
| 110 | Scope: name, |
| 111 | Kind: CacheKindPrefix, |
| 112 | ID: prefix, |
| 113 | }) |
| 114 | } |
| 115 | addPrefixVariants := func(prefix string) { |
| 116 | addPrefix(prefix) |
| 117 | if strings.HasSuffix(prefix, "/") { |
| 118 | addPrefix(strings.TrimSuffix(prefix, "/")) |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | addPrefix("") |
| 123 | parts := strings.Split(key, "/") |
| 124 | if len(parts) > 1 { |
| 125 | var b strings.Builder |
| 126 | for i := 0; i < len(parts)-1; i++ { |
| 127 | if parts[i] == "" { |
| 128 | continue |
| 129 | } |
| 130 | b.WriteString(parts[i]) |
| 131 | b.WriteByte('/') |
| 132 | addPrefixVariants(b.String()) |
| 133 | } |
| 134 | } |
| 135 | return refs |
| 136 | } |
| 137 | |
| 138 | // FilesystemPrefixRefs builds refs for a filesystem list prefix. The root |
| 139 | // prefix is included so broad filesystem invalidations can evict all entries. |