* Deletes the value associated with the given key. * * @experimental **UNSTABLE**: New API, yet to be vetted. * * @param key The key to delete. * @returns `true` if the key was deleted, `false` otherwise. * * @example Deleting a key from the cache * ```ts * import { LruCac
(key: K)
| 294 | * ``` |
| 295 | */ |
| 296 | override delete(key: K): boolean { |
| 297 | if (this.#ejecting) { |
| 298 | throw new TypeError( |
| 299 | "Cannot delete entry in LruCache: cache is not re-entrant during onEject callbacks", |
| 300 | ); |
| 301 | } |
| 302 | const value = super.get(key); |
| 303 | const existed = super.delete(key); |
| 304 | if (!existed) return false; |
| 305 | |
| 306 | if (this.#eject) { |
| 307 | this.#ejecting = true; |
| 308 | try { |
| 309 | this.#eject(key, value!, "deleted"); |
| 310 | } finally { |
| 311 | this.#ejecting = false; |
| 312 | } |
| 313 | } |
| 314 | return true; |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * Clears the cache. |