Skip to content

WeakCache is like WeakMap but extends support to primitive keys, and with both object keys and object values being weakly referenced.

License

Notifications You must be signed in to change notification settings

wopjs/weak-cache

Repository files navigation

@wopjs/weak-cache

Docs Build Status Coverage Status

npm-version minified-size no-dependencies tree-shakable side-effect-free

WeakCache is like WeakMap but extends support to primitive keys, and with both object keys and object values being weakly referenced.

Install

npm add @wopjs/weak-cache

Usage

import { WeakCache } from "@wopjs/weak-cache";

const cache = new WeakCache();

cache.set("key", { value: "value" });

const objectKey = { key: "key" };

cache.set(key, { value: "value" });

console.log(cache.size); // 2

console.log(cache.get("key")); // { value: "value" }
console.log(cache.get(objectKey)); // { value: "value" }

// ...
// gc()

console.log(cache.size); // 0

About

WeakCache is like WeakMap but extends support to primitive keys, and with both object keys and object values being weakly referenced.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published