{"id":47211,"library":"cacheable","title":"Cacheable","description":"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.","status":"active","version":"2.3.5","language":"javascript","source_language":"en","source_url":"https://github.com/jaredwray/cacheable","tags":["javascript","cacheable","high performance","layer 1 caching","layer 2 caching","distributed caching","Keyv storage engine","memory caching","LRU cache","typescript"],"install":[{"cmd":"npm install cacheable","lang":"bash","label":"npm"},{"cmd":"yarn add cacheable","lang":"bash","label":"yarn"},{"cmd":"pnpm add cacheable","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core storage abstraction providing the secondary store interface and underlying storage adapters.","package":"keyv","optional":false},{"reason":"Commonly used Redis storage adapter for layer 2 caching and distributed sync.","package":"@keyv/redis","optional":true}],"imports":[{"note":"Package exports named exports only. Default import is not available. ESM and CJS both supported via named export.","wrong":"const Cacheable = require('cacheable')","symbol":"Cacheable","correct":"import { Cacheable } from 'cacheable'"},{"note":"Named export for the in-memory cache class, not a default export.","wrong":"import CacheableMemory from 'cacheable'","symbol":"CacheableMemory","correct":"import { CacheableMemory } from 'cacheable'"},{"note":"Keyv storage adapter for CacheableMemory. Can be used as a Keyv store.","wrong":"const { KeyvCacheableMemory } = require('cacheable');","symbol":"KeyvCacheableMemory","correct":"import { KeyvCacheableMemory } from 'cacheable'"},{"note":"Available since v2. Provides distributed cache synchronization via pub/sub.","wrong":"","symbol":"CacheSync","correct":"import { CacheSync } from 'cacheable'"}],"quickstart":{"code":"import { Cacheable } from 'cacheable';\n\nconst cache = new Cacheable({ ttl: 60000 });\nawait cache.set('greeting', 'Hello, Cacheable!');\nconst value = await cache.get('greeting');\nconsole.log(value); // 'Hello, Cacheable!'\n\n// With secondary store (Redis)\nimport KeyvRedis from '@keyv/redis';\nconst secondary = new KeyvRedis('redis://localhost:6379');\nconst cache2 = new Cacheable({ secondary, ttl: '5m' });\nawait cache2.set('key', { data: 123 });\nconst result = await cache2.get('key');\nconsole.log(result); // { data: 123 }","lang":"typescript","description":"Basic setup with in-memory cache followed by example with Redis secondary store and shorthand TTL."},"warnings":[{"fix":"Set namespace option to empty string to restore v1 behavior: new Cacheable({ namespace: '' })","message":"v2 uses namespace 'cacheable' by default for key prefix, breaking cache keys from v1 which had no prefix.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always return a Promise from wrap callback, or use the new 'wrapSync' method for synchronous functions.","message":"The 'wrap' method signature changed: callback now returns a Promise in v2, synchronous callbacks are deprecated.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Set ttl explicitly either in constructor or on every set() call to avoid unintended eternal caching.","message":"The 'ttl' option in constructor applies to all operations, but individual set() calls can override. If ttl is not set, values never expire.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use Keyv's new serialize/deserialize options; see Keyv migration guide.","message":"Keyv v9 changed the way serialize/deserialize works; custom serialization options from v8 may not work.","severity":"breaking","affected_versions":">=2.0.0"}],"env_vars":null,"search_vec":"'1':5,103 '1d':64 '1h':63 '1m':62 '2':7,106 '2.3.5':19 'across':57 'activ':20 'block':50 'built':25,94 'built-in':93 'cach':8,36,69,85,104,107,109,114,116 'cacheabl':1,87,99 'cacheablememori':41 'cachesync':66 'commonj':80 'compar':81 'current':16 'differenti':53 'distribut':11,68,96,108 'engin':9,32,112 'enterpris':14 'esm':78 'expir':40 'featur':15 'fulli':73 'high':2,100 'hooks/events':46 'includ':54 'integr':91 'javascript':98 'key':52 'keyv':30,90,110 'layer':4,6,102,105 'lru':38,115 'maintain':21 'manag':86 'memori':35,113 'node':84 'node-cache-manag':83 'non':49 'non-block':48 'offer':88 'oper':51 'perform':3,101 'propag':56 'protect':45 'pub/sub':72 'regular':23 'releas':24 'shorthand':59 'stabl':17 'stamped':44 'storag':31,111 'string':61 'support':34,77 'sync':12,97 'tier':58 'tighter':89 'top':27 'ttl':55,60 'type':74 'typescript':76,117 'updat':70 'version':18 'via':71 'wrap/memoization':42","created_at":"2026-06-07T16:50:21.936132+00:00","updated_at":"2026-06-07T16:50:21.936132+00:00","problems":[{"fix":"Use named import: import { Cacheable } from 'cacheable'","cause":"Importing default export instead of named export: import Cacheable from 'cacheable'","error":"TypeError: cacheable.get is not a function"},{"fix":"Install @keyv/redis: npm install @keyv/redis","cause":"Missing optional dependency @keyv/redis when creating Cacheable with secondary Redis store.","error":"Error: Cannot find module '@keyv/redis'"},{"fix":"Ensure key is a non-empty string: cache.set('myKey', value)","cause":"Calling set() or get() with undefined key.","error":"ERR_INVALID_ARG_TYPE: The \"key\" argument must be of type string. Received undefined"},{"fix":"Pass a valid CacheableOptions object: { secondary?: Keyv, ttl?: number|string }","cause":"Passing invalid options object (e.g., missing secondary property when expected).","error":"TypeError: Cannot read properties of undefined (reading 'store')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/jaredwray/cacheable#readme","github":"https://github.com/jaredwray/cacheable","docs":null,"changelog":null,"pypi":null,"npm":"cacheable","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage","testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}