Registry / storage / cache-manager

cache-manager

JSON →
library7.2.8jsnpmunverified

Cache manager for Node.js (v7.2.8) providing a consistent interface for in-memory and distributed caching. Built on Keyv storage adapters supporting Redis, MongoDB, SQLite, and more. Key differentiators: simple wrapper for functions, tiered caches, background refresh of expiring keys, and non-blocking multi-store optimization. Actively maintained with 100% test coverage. Breaking change in v7: get returns undefined instead of null. Major v6 rewrite replaced custom stores with Keyv adapters.

npm install cache-manager
INSTALL
IMPORT
SIG · CACHE-MANAGER
C
cache-manager
storagejavascriptv7.2.8
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.

createCache
import { createCache } from 'cache-manager'
const cacheManager = require('cache-manager'); const cache = cacheManager.createCache()
ESM-only since v6; named export
memoryStore
import { memoryStore } from 'cache-manager'
import memoryStore from 'cache-manager'
Named export for configuring in-memory store specifically; omitted in default setup
caching
import { caching } from 'cache-manager'
const { caching } = require('cache-manager')
Deprecated in v6, use createCache instead

Shows basic set, get, and delete operations with TTL using memory store

import { createCache } from 'cache-manager'; const cache = createCache(); await cache.set('key', 'value', 5000); // TTL 5 seconds const value = await cache.get('key'); console.log(value); // 'value' await cache.del('key'); console.log(await cache.get('key')); // undefined
Debug
Known issues
breakingv7 changed return type of get() from null to undefined for missing keys
fix
Replace null checks with undefined checks (e.g., if (result !== undefined))
affects: >=7.0.0
breakingv6 replaced storage backends with Keyv adapters; old store APIs removed
fix
Use createCache() with Keyv stores instead of memoryStore() etc.
affects: >=6.0.0
deprecatedcaching() function deprecated in v6; use createCache()
fix
Replace caching() with createCache()
affects: >=6.0.0
gotchaWhen using in-memory cache, objects like Uint8Array may be serialized incorrectly due to JSON serialization in Keyv
fix
Set { serialization: undefined, deserialization: undefined } in Keyv options for binary data
affects: >=6.0.0
gotchaESM-only since v6; require() will not work
fix
Use import syntax or dynamic import()
affects: >=6.0.0
Errors
Common errors & fixes
TypeError: cache.get is not a function
Importing default export instead of named export
fix
Use import { createCache } from 'cache-manager'
Cannot find module 'cache-manager' or its corresponding type declarations
TypeScript project missing types
fix
Ensure tsconfig.json includes 'esModuleInterop': true and 'moduleResolution': 'node'
TypeError: store.get is not a function
Using v5 store API with v6 createCache
fix
Pass Keyv instances via stores array, not old store functions
Upgrade
Version history
7.2.8latest on npm
Audit
Dependencies
keyvrequiredUnderlying storage abstraction used by all adapters
Agent activity
31 hits · last 30 days
node
29
Resources
cache-manager — npm install cache-manager · libregistry