Registry / database / lru-cache-for-clusters-as-promised

lru-cache-for-clusters-as-promised

JSON →
library2.1.0jsnpmunverified

LRU cache for Node.js cluster mode (v2.1.0). Eliminates per-worker cache duplication by hosting a single lru-cache instance in the primary process and exposing it to workers over cluster IPC. Supports atomic counters, single-flight fetches, optional L1 hot caches, and pluggable codecs. Requires Node >=22 and lru-cache ^11. Compared to standalone lru-cache, this package provides cluster-wide consistency and memory savings without external dependencies like Redis.

npm install lru-cache-for-clusters-as-promised
INSTALL
IMPORT
SIG · LRU-CACHE-FOR-CLUS
L
lru-cache-for-clusters-as-promised
databasejavascriptv2.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LRUCacheClustered
import { LRUCacheClustered } from '@0xdoublesharp/lru-cache-clustered'
const LRUCacheClustered = require('@0xdoublesharp/lru-cache-clustered')
ESM-only package. CommonJS require will throw ERR_REQUIRE_ESM.
createCache
import { createCache } from '@0xdoublesharp/lru-cache-clustered'
import { createCache } from '@0xdoublesharp/lru-cache-clustered/createCache'
createCache is a top-level export, not a subpath export.
CacheTypes
import type { CacheTypes } from '@0xdoublesharp/lru-cache-clustered'
import { CacheTypes } from '@0xdoublesharp/lru-cache-clustered'
CacheTypes is a type-only export. Use import type to avoid runtime issues.
wrapCodec
import { wrapCodec } from '@0xdoublesharp/lru-cache-clustered'
import { wrapCodec } from '@0xdoublesharp/lru-cache-clustered/wrapCodec'
wrapCodec is a top-level export, not a subpath.

Shows how to create a clustered LRU cache in the primary and use it from a worker. Both primary and worker must call ready() before use.

import cluster from 'node:cluster'; import { LRUCacheClustered } from '@0xdoublesharp/lru-cache-clustered'; if (cluster.isPrimary) { const cache = new LRUCacheClustered({ namespace: 'my-cache', max: 1000, ttl: 60_000, }); await cache.ready(); console.log('Primary cache ready'); } else { const cache = new LRUCacheClustered({ namespace: 'my-cache', max: 1000, ttl: 60_000, }); await cache.ready(); await cache.set('key', 'value'); const value = await cache.get('key'); console.log('Worker got:', value); await cache.disconnect(); process.exit(0); }
Debug
Known issues
breakingRequires Node >= 22. Older Node versions are not supported.
fix
Upgrade Node to >=22 or use an older version of the package (v1.x may support older Node).
affects: >=1.0.0 <2.0.0?
breakingPeer dependency lru-cache ^11 is required. Incompatible with lru-cache v10 or earlier.
fix
Install lru-cache@^11 alongside this package.
affects: >=2.0.0
deprecatedv1.x used a different API (e.g., createCache() might have been the only way). Upgrade to v2 for new features and ESM support.
fix
Upgrade to v2 and update imports accordingly.
affects: <2.0.0
gotchaWorkers must call cache.ready() before using the cache. Operations before ready() will throw or queue indefinitely.
fix
Always await cache.ready() after constructing the cache instance.
affects: >=2.0.0
gotchaThe package is ESM-only. CommonJS require() will fail with ERR_REQUIRE_ESM.
fix
Use import syntax or dynamic import().
affects: >=2.0.0
gotchaCache namespace must be unique per cache instance. Sharing a namespace across different cache configurations can cause undefined behavior.
fix
Use distinct namespace strings for different cache instances.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module not supported
Package is ESM-only, but CommonJS require() was used.
fix
Change require() to import or use dynamic import().
TypeError: cache.ready is not a function
Attempted to call cache.ready() before cache instantiation completed or on a wrong reference.
fix
Ensure cache is created with new LRUCacheClustered() and wait for ready().
Error: Namespace 'my-cache' already registered
Two cache instances with the same namespace were created in the same primary process.
fix
Use unique namespace strings for each cache instance.
MODULE_NOT_FOUND: Cannot find module 'lru-cache'
Peer dependency lru-cache is not installed.
fix
Run npm install @0xdoublesharp/lru-cache-clustered lru-cache.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
lru-cacherequiredPeer dependency; provides the underlying cache implementation.
Agent activity
6 hits · last 30 days
node
4
Resources
lru-cache-for-clusters-as-promised — npm install lru-cache-for-clusters-as-promised · libregistry