Registry / storage / cacheable

cacheable

JSON →
library2.3.5jsnpmunverified

High performance layer 1 / layer 2 caching engine with distributed sync and enterprise features. Current stable version 2.3.5, actively maintained with regular releases. Built on top of the Keyv storage engine, it supports memory caching with LRU and expiration (CacheableMemory), wrap/memoization with stampede protection, hooks/events, and non-blocking operations. Key differentiators include TTL propagation across tiers, shorthand TTL strings (1m, 1h, 1d), and CacheSync for distributed cache updates via pub/sub. Fully typed with TypeScript, supports ESM and CommonJS. Compared to node-cache-manager, Cacheable offers tighter Keyv integration and built-in distributed sync.

npm install cacheable
INSTALL
IMPORT
SIG · CACHEABLE
C
cacheable
storagejavascriptv2.3.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.

Cacheable
import { Cacheable } from 'cacheable'
const Cacheable = require('cacheable')
Package exports named exports only. Default import is not available. ESM and CJS both supported via named export.
CacheableMemory
import { CacheableMemory } from 'cacheable'
import CacheableMemory from 'cacheable'
Named export for the in-memory cache class, not a default export.
KeyvCacheableMemory
import { KeyvCacheableMemory } from 'cacheable'
const { KeyvCacheableMemory } = require('cacheable');
Keyv storage adapter for CacheableMemory. Can be used as a Keyv store.
CacheSync
import { CacheSync } from 'cacheable'
Available since v2. Provides distributed cache synchronization via pub/sub.

Basic setup with in-memory cache followed by example with Redis secondary store and shorthand TTL.

import { Cacheable } from 'cacheable'; const cache = new Cacheable({ ttl: 60000 }); await cache.set('greeting', 'Hello, Cacheable!'); const value = await cache.get('greeting'); console.log(value); // 'Hello, Cacheable!' // With secondary store (Redis) import KeyvRedis from '@keyv/redis'; const secondary = new KeyvRedis('redis://localhost:6379'); const cache2 = new Cacheable({ secondary, ttl: '5m' }); await cache2.set('key', { data: 123 }); const result = await cache2.get('key'); console.log(result); // { data: 123 }
Debug
Known issues
breakingv2 uses namespace 'cacheable' by default for key prefix, breaking cache keys from v1 which had no prefix.
fix
Set namespace option to empty string to restore v1 behavior: new Cacheable({ namespace: '' })
affects: >=2.0.0
deprecatedThe 'wrap' method signature changed: callback now returns a Promise in v2, synchronous callbacks are deprecated.
fix
Always return a Promise from wrap callback, or use the new 'wrapSync' method for synchronous functions.
affects: >=2.0.0
gotchaThe 'ttl' option in constructor applies to all operations, but individual set() calls can override. If ttl is not set, values never expire.
fix
Set ttl explicitly either in constructor or on every set() call to avoid unintended eternal caching.
affects: >=1.0.0
breakingKeyv v9 changed the way serialize/deserialize works; custom serialization options from v8 may not work.
fix
Use Keyv's new serialize/deserialize options; see Keyv migration guide.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: cacheable.get is not a function
Importing default export instead of named export: import Cacheable from 'cacheable'
fix
Use named import: import { Cacheable } from 'cacheable'
Error: Cannot find module '@keyv/redis'
Missing optional dependency @keyv/redis when creating Cacheable with secondary Redis store.
fix
Install @keyv/redis: npm install @keyv/redis
ERR_INVALID_ARG_TYPE: The "key" argument must be of type string. Received undefined
Calling set() or get() with undefined key.
fix
Ensure key is a non-empty string: cache.set('myKey', value)
TypeError: Cannot read properties of undefined (reading 'store')
Passing invalid options object (e.g., missing secondary property when expected).
fix
Pass a valid CacheableOptions object: { secondary?: Keyv, ttl?: number|string }
Upgrade
Version history
2.3.5latest on npm
Audit
Dependencies
keyvrequiredCore storage abstraction providing the secondary store interface and underlying storage adapters.
@keyv/redisoptionalCommonly used Redis storage adapter for layer 2 caching and distributed sync.
Agent activity
36 hits · last 30 days
node
34
Resources
cacheable — npm install cacheable · libregistry