New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@endo/cache-map

Package Overview
Dependencies
Maintainers
5
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@endo/cache-map

bounded-size caches having WeakMap-compatible methods

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
138K
11.1%
Maintainers
5
Weekly downloads
 
Created
Source

cache-map

This @endo/cache-map package creates bounded-size caches having WeakMap-compatible has/get/set/delete methods. Key validity, comparison, and referential strength are controlled by a makeMap option, which defaults to WeakMap but can be set to any producer of objects with those methods (e.g., using Map allows for arbitrary keys which will be strongly held). Cache eviction policy is not currently configurable, but strives for a hit ratio at least as good as LRU (e.g., it might be CLOCK or SIEVE).

Usage

Weak Cache

import { makeCacheMapKit } from '@endo/cache-map';

const { cache: weakCache, getMetrics } = makeCacheMapKit(2);
const entries = [
  { key: Symbol('key 1'), value: Symbol('value 1') },
  { key: Symbol('key 2'), value: Symbol('value 2') },
  { key: Symbol('key 3'), value: Symbol('value 3') },
];
for (const { key, value } of entries) weakCache.set(key, value);

assert(!weakCache.has(entries[0].key));
assert(weakCache.has(entries[1].key));
assert(weakCache.get(entries[2].key) === entries[2].value);

weakCache.delete(entries[2].key);
weakCache.set(entries[1].key, entries[0]);

assert(!weakCache.has(entries[0].key));
assert(!weakCache.has(entries[2].key));
assert(weakCache.get(entries[1].key) === entries[0]);

assert.throws(() => weakCache.set('unweakable key', {}));

Strong Cache

import { makeCacheMapKit } from '@endo/cache-map';

const { cache, getMetrics } = makeCacheMapKit(100, { makeMap: Map });
cache.set('unweakable key', 'ok');
assert(cache.get('unweakable key') === 'ok');

License

Apache License, Version 2.0

Keywords

cache

FAQs

Package last updated on 12 Jul 2025

Did you know?

Socket

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.

Install

Related posts