Registry / database / memoize-cache

memoize-cache

JSON →
library6.0.5jsnpmunverified

Configurable cache support for memoized functions, providing base-cache prototype, in-memory RAM cache (cache-ram), and no-cache mock for testing. Current stable version is 6.0.5, with irregular release cadence. Supports LRU eviction, TTL (maxAge), stale-while-revalidate (maxValidity), tag-based invalidation, custom serialization/deserialization, and custom key extraction. Designed to integrate with async-deco and has adapters for cache-manager and Redis via companion packages. Suitable for both Node.js and browser environments.

npm install memoize-cache
INSTALL
IMPORT
SIG · MEMOIZE-CACHE
M
memoize-cache
databasejavascriptv6.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.

CacheRAM
import { CacheRAM } from 'memoize-cache'
import CacheRAM from 'memoize-cache'
Default export is an object with named exports; named import required.
base-cache constructor
import { BaseCache } from 'memoize-cache'
const BaseCache = require('memoize-cache').BaseCache
ESM named import; CommonJS require works but ESM is preferred.
NoCache
import { NoCache } from 'memoize-cache'
Available as named export.
cache-ram (CommonJS require with subpath)
const CacheRAM = require('memoize-cache/cache-ram')
const cache = require('memoize-cache')
Subpath import for cache-ram only; main export is the full module.

Shows initialization with custom key extraction from first argument, LRU limit, TTL, then pushing and querying cached values.

import { CacheRAM } from 'memoize-cache'; const cache = new CacheRAM({ getKey: (args) => args[0].id, maxLen: 100, maxAge: 20000 }); // Cache result of a function call const result = expensiveComputation({ id: 1 }); cache.push([{ id: 1 }], result); // Query cached value cache.query([{ id: 1 }], (err, cached) => { if (err) console.error(err); else console.log('Cached:', cached); });
Debug
Known issues
gotchaThe 'getKey' function receives an array of arguments (args), not individual arguments. Common mistake is to destructure incorrectly.
fix
Ensure getKey receives the full args array: getKey: (args) => args[0].id.
affects: >=1.0.0
gotchaTime units for maxAge and maxValidity are milliseconds, not seconds. Documentation says seconds but implementation uses milliseconds.
fix
Pass values in milliseconds: maxAge: 20000 for 20 seconds.
affects: >=6.0.0
deprecatedThe 'seconds' documentation for maxAge is deprecated; expect version 7 to align with milliseconds.
fix
Continue using milliseconds; upcoming major may change to seconds.
affects: >=6.0.0 <7.0.0
gotchaSubpath imports like 'memoize-cache/cache-ram' may not be typed correctly in TypeScript if no declaration file exists for that path.
fix
Use main import and destructure: import { CacheRAM } from 'memoize-cache'.
affects: >=6.0.0
gotchaUsing require('memoize-cache') in CommonJS returns an object with named properties, not the constructor directly.
fix
Use const { CacheRAM } = require('memoize-cache');
affects: >=6.0.0
Errors
Common errors & fixes
TypeError: cache_ram_1.default is not a constructor
Using default import instead of named import.
fix
Change to: import { CacheRAM } from 'memoize-cache';
Error: getKey is not a function
getKey not provided or passed incorrectly; it receives args array.
fix
Ensure getKey is a function that takes args: getKey: (args) => args[0].id
Error: Cannot find module 'memoize-cache/cache-ram'
Using subpath require that does not exist in older versions.
fix
Use require('memoize-cache') and destructure CacheRAM.
Upgrade
Version history
6.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
memoize-cache — npm install memoize-cache · libregistry