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

Method clear

cache/lru_cache.ts:335–361  ·  view source on GitHub ↗

* Clears the cache. * * @experimental **UNSTABLE**: New API, yet to be vetted. * * @example Usage * ```ts * import { LruCache } from "@std/cache"; * import { assertEquals } from "@std/assert/equals"; * * const cache = new LruCache (100); * * cache.set(

()

Source from the content-addressed store, hash-verified

333 * ```
334 */
335 override clear(): void {
336 if (this.#ejecting) {
337 throw new TypeError(
338 "Cannot clear LruCache: cache is not re-entrant during onEject callbacks",
339 );
340 }
341 if (!this.#eject) {
342 super.clear();
343 return;
344 }
345 const entries = [...super.entries()];
346 super.clear();
347 this.#ejecting = true;
348 let error: unknown;
349 try {
350 for (const [key, value] of entries) {
351 try {
352 this.#eject(key, value, "cleared");
353 } catch (e) {
354 error ??= e;
355 }
356 }
357 } finally {
358 this.#ejecting = false;
359 }
360 if (error !== undefined) throw error;
361 }
362}

Callers

nothing calls this directly

Calls 2

clearMethod · 0.65
entriesMethod · 0.45

Tested by

no test coverage detected