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 cacheableNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic setup with in-memory cache followed by example with Redis secondary store and shorthand TTL.
Set namespace option to empty string to restore v1 behavior: new Cacheable({ namespace: '' })Always return a Promise from wrap callback, or use the new 'wrapSync' method for synchronous functions.
Set ttl explicitly either in constructor or on every set() call to avoid unintended eternal caching.
Use Keyv's new serialize/deserialize options; see Keyv migration guide.
Use named import: import { Cacheable } from 'cacheable'Install @keyv/redis: npm install @keyv/redis
Ensure key is a non-empty string: cache.set('myKey', value)Pass a valid CacheableOptions object: { secondary?: Keyv, ttl?: number|string }