Registry / messaging / rabbit-lru-cache

rabbit-lru-cache

JSON →
library5.0.0jsnpmunverified

Distributed LRU cache invalidation via RabbitMQ, built on top of lru-cache and amqplib. Current stable version 5.0.0 (Node >=20). Provides automatic cache invalidation across multiple instances when a key is deleted or cache is cleared via RabbitMQ fanout exchange. Key differentiators: built-in reconnection with automatic cache reset, concurrency handling (Thundering herd protection) via getOrLoad, and TypeScript support. Release cadence: mature, actively maintained.

npm install rabbit-lru-cache
INSTALL
IMPORT
SIG · RABBIT-LRU-CACHE
R
rabbit-lru-cache
messagingjavascriptv5.0.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.

default
import createRabbitLRUCache from 'rabbit-lru-cache'
const createRabbitLRUCache = require('rabbit-lru-cache').default
ESM default import; CJS require needs `.default` since the package is ESM-only.
RabbitLRUCache
import type { RabbitLRUCache } from 'rabbit-lru-cache'
import { RabbitLRUCache } from 'rabbit-lru-cache'
Type import only; RabbitLRUCache is a TypeScript interface, not a value.
RabbitLRUCacheOptions
import type { RabbitLRUCacheOptions } from 'rabbit-lru-cache'
const RabbitLRUCacheOptions = require('rabbit-lru-cache').RabbitLRUCacheOptions
Type-only import.

Creates a distributed LRU cache, adds a listener for invalidation messages, uses getOrLoad to fetch/cache a value, deletes the key, and gracefully closes.

import createRabbitLRUCache from 'rabbit-lru-cache'; const cache = await createRabbitLRUCache({ name: 'example', LRUCacheOptions: { ttl: 120000, max: 10000 }, amqpConnectOptions: { hostname: process.env.RABBIT_HOST ?? 'localhost', username: process.env.RABBIT_USER ?? 'guest', password: process.env.RABBIT_PASS ?? 'guest' } }); // Listen for invalidation messages cache.addInvalidationMessageReceivedListener((content, publisherCacheId) => { console.log('Invalidation received from', publisherCacheId, ':', content); }); // Use getOrLoad to fetch and cache const value = await cache.getOrLoad('key', () => Promise.resolve(42)); console.log(value); // 42 // Deleting a key sends invalidation to all instances cache.delete('key'); // Gracefully close await cache.close();
Debug
Known issues
gotcharequire('rabbit-lru-cache').default is required for CJS; direct require returns an object with `default` property (ESM behavior)
fix
Use import createRabbitLRUCache from 'rabbit-lru-cache' in ESM, or const createRabbitLRUCache = require('rabbit-lru-cache').default in CJS.
affects: >=5.0.0
breakingNode >=20 required since v5.0.0; older Node versions not supported
fix
Upgrade Node to version 20 or later.
affects: >=5.0.0
gotchaCache is disabled during RabbitMQ reconnection; local cache is reset to avoid stale data
fix
Handle getOrLoad failures or cache misses during reconnection by retrying or using fallback.
affects: *
gotchadelete and clear operations publish to a fanout exchange; ensure RabbitMQ exchange exists or library creates it
fix
Verify RabbitMQ permissions for exchange creation on the virtual host.
affects: *
Errors
Common errors & fixes
TypeError: createRabbitLRUCache is not a function
Using CJS require without .default
fix
Use const createRabbitLRUCache = require('rabbit-lru-cache').default;
Error: Cannot find module 'rabbit-lru-cache'
Package not installed or missing from node_modules
fix
Run npm install rabbit-lru-cache
error:0308010C:digital envelope routines::unsupported
Running on Node.js <20 with incompatible OpenSSL
fix
Upgrade to Node >=20 as required by v5.0.0
Upgrade
Version history
5.0.0latest on npm
Audit
Dependencies
lru-cacherequiredLRU cache implementation
amqplibrequiredRabbitMQ client for messaging
Agent activity
12 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
rabbit-lru-cache — npm install rabbit-lru-cache · libregistry