* Delete a key (clears version and all cached values).
(key: K)
| 134 | * Delete a key (clears version and all cached values). |
| 135 | */ |
| 136 | delete(key: K): void { |
| 137 | if (!this.versions.has(key)) return; |
| 138 | |
| 139 | // Clear all cached values for this key |
| 140 | const keyStr = String(key); |
| 141 | for (const cacheKey of Array.from(this.cache.keys())) { |
| 142 | if (cacheKey.startsWith(`${keyStr}:`)) { |
| 143 | this.cache.delete(cacheKey); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | this.versions.delete(key); |
| 148 | |
| 149 | // Notify |
| 150 | for (const l of this.global) l(); |
| 151 | const ks = this.perKey.get(key); |
| 152 | if (ks) { |
| 153 | for (const l of ks) l(); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Clear all data. |