Registry / database / memory-cache-node

memory-cache-node

JSON →
library1.4.0jsnpmunverified

Fast, modern, and event-loop non-blocking memory cache for Node.js and browser. Version 1.4.0 is the current stable release, with regular updates. Uses JavaScript Map for faster lookups compared to plain object caches, and implements non-blocking cleanup for large caches (hundreds of thousands to millions of entries). Supports TypeScript with built-in types. Ideal for in-memory caching with configurable expiration intervals and max item counts.

npm install memory-cache-node
INSTALL
IMPORT
SIG · MEMORY-CACHE-NODE
M
memory-cache-node
databasejavascriptv1.4.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.

MemoryCache
import { MemoryCache } from 'memory-cache-node'
import MemoryCache from 'memory-cache-node'
The package only exports a named export, not a default one.

Creates a cache with 10-min expiration check, max 1M items; stores permanent and expiring items; retrieves and checks existence.

import { MemoryCache } from 'memory-cache-node'; const cache = new MemoryCache<string, number>(600, 1000000); cache.storePermanentItem('key1', 42); cache.storeExpiringItem('key2', 100, 300); console.log(cache.retrieveItemValue('key1')); // 42 console.log(cache.hasItem('key2')); // true console.log(cache.getItemCount()); // 2
Debug
Known issues
gotchaThe interval for expiration check is in seconds, but the time-to-live for expiring items is also in seconds.
fix
Ensure both values are provided in seconds, not milliseconds.
affects: >=1.0.0
breakingVersions prior to 1.0.0 had a different API.
fix
Upgrade to 1.x and adapt to the current API.
affects: <1.0.0
gotchastorePermanentItem stores an item that never expires; it is not removed by expiration checks.
fix
Use storeExpiringItem with a large TTL if you want items to be cleaned up eventually.
affects: >=1.0.0
gotcharetrieveItemValue returns undefined for missing keys, not null.
fix
Check using hasItem before retrieving, or handle undefined.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'memory-cache-node'
Package not installed or not in node_modules.
fix
Run 'npm install memory-cache-node' or add to package.json.
TypeError: memoryCache.storePermanentItem is not a function
Using incorrect import (e.g., default import instead of named import).
fix
Use correct import: import { MemoryCache } from 'memory-cache-node';
TypeError: Class extends value undefined is not a constructor or null
Importing from a wrong path or using an older version without proper exports.
fix
Update to version >=1.0.0 and use the named import.
Upgrade
Version history
1.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Amazon
1
Resources
memory-cache-node — npm install memory-cache-node · libregistry