
Company News
Free Business Plan Upgrades for Open Source Maintainers
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.
weakref-store
Advanced tools
A WeakRef-based cache that automatically evicts entries when values are garbage collected
A WeakRef-based cache that automatically evicts entries when values are garbage collected
npm install weakref-store
import WeakCache from 'weakref-store';
const cache = new WeakCache({
onEvict(key) {
console.log(`${key} was garbage collected`);
},
});
let value = {data: 'hello'};
cache.set('key', value);
console.log(cache.get('key'));
//=> {data: 'hello'}
console.log(cache.has('key'));
//=> true
Type: object
Type: (key) => void
Callback invoked with the key when an entry is evicted by garbage collection.
Returns the value for the key, or undefined if the key does not exist or its value has been garbage collected.
Set a key-value pair. The value must be an object (required for WeakRef). Throws TypeError for primitives.
Returns true if the key exists and the value is still alive.
Removes an entry. Returns true if the entry existed.
The approximate number of entries. May include entries whose values have been collected but not yet finalized.
MIT
FAQs
A WeakRef-based cache that automatically evicts entries when values are garbage collected
We found that weakref-store demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.

Security News
The supply chain control that delays freshly published gems now covers lockfile generation and gem vendoring in Ruby projects.

Security News
During a UK cyber test, a Mythos 5 agent used sockpuppets, social engineering, and prompt injection to try to get a maintainer to merge malware.