Registry / storage / expiring-lru-cache

expiring-lru-cache

JSON →
library2.1.0jsnpmunverified

Expiring LRU cache for Node.js built on top of lru-cache. Version 2.1.0 adds support for Bunyan logging and configurable item expiry. Provides a simple key-value store with LRU eviction and TTL per item. Differentiators: integrates with Bunyan for trace-level logging, lightweight wrapper around lru-cache. No breaking changes reported. Low release cadence (last release 2015). Minimal dependencies.

npm install expiring-lru-cache
INSTALL
IMPORT
SIG · EXPIRING-LRU-CACHE
E
expiring-lru-cache
storagejavascriptv2.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.

Cache
const Cache = require('expiring-lru-cache');
import Cache from 'expiring-lru-cache';
Package is CJS-only, no ESM exports. Must use require().
new Cache(options)
const cache = new Cache({size: 100, expiry: 300});
Constructor expects object with 'size' (max items) and 'expiry' (seconds). Optional 'log' (Bunyan instance) and 'name'.
cache.set(key, value)
cache.set('key', value);
cache.set('key', value, expiry);
No per-item TTL; expiry is global per cache instance.
cache.get(key)
const val = cache.get('key');
Returns undefined if key not found or expired.
cache.del(key)
cache.del('key');
cache.delete('key');
Method name is 'del', not 'delete'.
cache.reset()
cache.reset();
Clears all entries.

Shows basic usage: instantiate cache with size and expiry, set/get/delete items.

const Cache = require('expiring-lru-cache'); // Create cache: max 100 items, items expire after 300 seconds const cache = new Cache({ size: 100, expiry: 300 }); cache.set('user:1', { name: 'Alice' }); const user = cache.get('user:1'); console.log(user); // => { name: 'Alice' } // After 300 seconds: setTimeout(() => { console.log(cache.get('user:1')); // => undefined }, 301 * 1000); cache.del('user:1'); cache.reset();
Debug
Known issues
gotchaItem expiry is global per cache, not per key. All items share the same TTL.
fix
If per-key TTL needed, use another library (e.g., lru-cache built-in TTL).
affects: >=1.0
deprecatedPackage uses deprecated Node.js APIs (no updates since 2015).
fix
Consider migrating to lru-cache@6+ which supports per-item ttl and better performance.
affects: >=2.0
gotchaBunyan optional logger: use 'log' option. If provided, cache may log at TRACE level.
fix
Ensure Bunyan is installed if you enable logging, or omit the log option.
affects: >=2.0
gotchaNo type definitions; TypeScript users must declare module manually.
fix
Create a .d.ts file or use require() with @types/node.
affects: >=1.0
Errors
Common errors & fixes
Cache is not a constructor
Using ES6 import instead of require()
fix
Use const Cache = require('expiring-lru-cache');
cache.set is not a function
Incorrect instantiation, likely missing 'new'
fix
Use 'new Cache({size: 100, expiry: 300})'
Cannot find module 'lru-cache'
Missing peer dependency
fix
Run 'npm install lru-cache' alongside expiring-lru-cache
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
lru-cacherequiredcore caching logic
Agent activity
21 hits · last 30 days
node
20
Resources
expiring-lru-cache — npm install expiring-lru-cache · libregistry