MCPcopy Create free account
hub / github.com/denoland/std / clear

Method clear

cache/ttl_cache.ts:319–337  ·  view source on GitHub ↗

* 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

()

Source from the content-addressed store, hash-verified

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

Callers 1

[Symbol.dispose]Method · 0.95

Calls 3

valuesMethod · 0.80
clearMethod · 0.65
entriesMethod · 0.45

Tested by

no test coverage detected