Registry / storage / mem-cache

mem-cache

JSON →
library0.0.5jsnpmunverified

Simple in-memory key/value cache for Node.js with automatic timeout-based expiration. Version 0.0.5 is the current stable release. The library provides basic cache operations (set, get, remove, clean) and emits events on entry expiration. It differs from more complex caching solutions (e.g., node-cache, lru-cache) by its minimal API and lack of advanced features like LRU eviction or TTL per entry. It is lightweight but offers configurable global timeout, optional timeout renewal on access, and the ability to disable timeout entirely.

npm install mem-cache
INSTALL
IMPORT
SIG · MEM-CACHE
M
mem-cache
storagejavascriptv0.0.5
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
✓ var Cache = require('mem-cache');
✗ import Cache from 'mem-cache';
This package is CommonJS only; ESM import will fail.
Cache
✓ var cache = new Cache();
✗ var cache = new Cache({});
Constructor with empty object is fine but unnecessary; omit if using defaults.
set
✓ cache.set('key', value);
✗ cache.set('key', value, 1000);
Timeout is optional; calling with 3 args is valid only if using custom timeout.

Shows basic usage: create cache with 5-second timeout, set and get value, then confirm auto-expiration.

var Cache = require('mem-cache'); var cache = new Cache({ timeout: 5000 }); cache.set('foo', 'bar'); console.log(cache.get('foo')); // 'bar' setTimeout(function() { console.log(cache.get('foo')); // null after 5 seconds }, 6000);
Debug
Known issues
gotchaMemory leak risk: cache entries with no timeout (timeoutDisabled: true) never expire and can accumulate.
fix
Set timeoutDisabled: false and ensure appropriate timeout values, or manually clean cache.
affects: >=0.0.0
deprecatedNo updates since 2013; package may have unpatched vulnerabilities.
fix
Consider using node-cache or lru-cache which are actively maintained.
affects: >=0.0.0
gotchaThe 'keys' property includes expired but not yet cleaned entries; length may not reflect active entries.
fix
Use 'keys' only for debugging; rely on 'length' after ensuring no expired items remain.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'mem-cache'
Package not installed or misspelled.
fix
Run 'npm install mem-cache' and verify package.json.
TypeError: cache.get is not a function
Using import statement incorrectly or cache is not instantiated via new.
fix
Use 'require' and 'new Cache()' as shown in docs.
undefined is not a function
Calling cache() instead of new Cache().
fix
Use 'var cache = new Cache();'
Upgrade
Version history
0.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
16
Resources
mem-cache — npm install mem-cache · libregistry