* Clears the cache. * * @experimental **UNSTABLE**: New API, yet to be vetted. * * @example Usage * ```ts * import { TtlCache } from "@std/cache"; * import { assertEquals } from "@std/assert/equals"; * * const cache = new TtlCache (1000); * * cache.set
()
| 317 | * ``` |
| 318 | */ |
| 319 | override clear(): void { |
| 320 | for (const timeout of this.#timeouts.values()) { |
| 321 | clearTimeout(timeout); |
| 322 | } |
| 323 | this.#timeouts.clear(); |
| 324 | this.#entryTtls?.clear(); |
| 325 | this.#absoluteDeadlines?.clear(); |
| 326 | const entries = [...super.entries()]; |
| 327 | super.clear(); |
| 328 | let error: unknown; |
| 329 | for (const [key, value] of entries) { |
| 330 | try { |
| 331 | this.#eject?.(key, value); |
| 332 | } catch (e) { |
| 333 | error ??= e; |
| 334 | } |
| 335 | } |
| 336 | if (error !== undefined) throw error; |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * Automatically clears all remaining timeouts once the cache goes out of |
no test coverage detected