{"id":44528,"library":"cajache","title":"cajache","description":"cajache is a minimalistic in-memory caching library for JavaScript/TypeScript (v2.0.2, released 2023). It provides a simple API to cache any asynchronous function result, with optional TTL support and configurable expiration check intervals. Unlike larger caching libraries like node-cache or lru-cache, cajache has zero dependencies and is very lightweight (~1KB minzipped). Its key differentiator is the `.use()` method that automatically handles cache miss/miss logic, reducing boilerplate. The library supports persistent (no TTL) and time-based caching, multiple instances, and path-based caching for nested results. It ships TypeScript definitions.","status":"active","version":"2.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/Icaruk/cajache","tags":["javascript","js","node","cache","caching","save","memcached","memory","typescript"],"install":[{"cmd":"npm install cajache","lang":"bash","label":"npm"},{"cmd":"yarn add cajache","lang":"bash","label":"yarn"},{"cmd":"pnpm add cajache","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM default import works directly. No .default needed in ESM.","wrong":"const cajache = require('cajache').default","symbol":"default","correct":"import cajache from 'cajache'"},{"note":"Named export for the class when using TypeScript types.","wrong":"const Cajache = require('cajache').Cajache","symbol":"Cajache","correct":"import { Cajache } from 'cajache'"},{"note":"CommonJS require works as shown in README. No .default needed.","wrong":"","symbol":"default (require)","correct":"const cajache = require('cajache')"}],"quickstart":{"code":"import cajache from 'cajache';\n\nasync function main() {\n  // Permanent cache\n  const response1 = await cajache.use(\n    'myKey',\n    () => fetch('https://api.example.com/data').then(r => r.json())\n  );\n  console.log(response1); // Fetches first time\n\n  const response2 = await cajache.use(\n    'myKey',\n    () => fetch('https://api.example.com/data').then(r => r.json())\n  );\n  console.log(response2); // Returns cached value\n\n  // TTL cache (1 second)\n  const response3 = await cajache.use(\n    'myKey2',\n    () => fetch('https://api.example.com/other').then(r => r.json()),\n    { ttl: 1000 }\n  );\n  console.log(response3);\n\n  // Creating isolated instance\n  const myCache = cajache.new();\n  const response4 = await myCache.use(\n    'key',\n    () => Promise.resolve('cached value')\n  );\n  console.log(response4); // 'cached value'\n}\n\nmain();","lang":"typescript","description":"Shows basic usage of cajache: permanent caching, TTL caching, and creating a new instance."},"warnings":[{"fix":"Wrap any pre-existing promise in an arrow function: `() => myPromise`.","message":"The `.use()` method always expects a function as second argument; passing a promise directly may cause unhandled rejections or unexpected behavior.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set `checkInterval` in constructor options to a smaller value if more immediate cleanup is needed.","message":"TTL expiration check interval defaults to 60 seconds. This means expired entries may not be cleaned up immediately; they are only purged on get or during the periodic check.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure the path only references simple object keys without dots or special characters.","message":"The `path` option uses dot notation but does not support array indices or bracket notation for nested properties with special characters.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1kb':56 '2023':15 'api':20 'asynchron':24 'automat':66 'base':82,89 'boilerpl':72 'cach':9,22,38,43,47,68,83,90,101,102 'cajach':1,2,48 'check':34 'configur':32 'definit':97 'depend':51 'differenti':60 'expir':33 'function':25 'handl':67 'in-memori':6 'instanc':85 'interv':35 'javascript':98 'javascript/typescript':12 'js':99 'key':59 'larger':37 'librari':10,39,74 'lightweight':55 'like':40 'logic':70 'lru':46 'lru-cach':45 'memcach':104 'memori':8,105 'method':64 'minimalist':5 'minzip':57 'miss/miss':69 'multipl':84 'nest':92 'node':42,100 'node-cach':41 'option':28 'path':88 'path-bas':87 'persist':76 'provid':17 'reduc':71 'releas':14 'result':26,93 'save':103 'ship':95 'simpl':19 'support':30,75 'time':81 'time-bas':80 'ttl':29,78 'typescript':96,106 'unlik':36 'use':63 'v2.0.2':13 'zero':50","created_at":"2026-06-07T12:50:35.150833+00:00","updated_at":"2026-06-07T12:50:35.150833+00:00","problems":[{"fix":"Use `const cajache = require('cajache')` for CommonJS, or `import cajache from 'cajache'` for ESM.","cause":"Using default import with CommonJS require incorrectly.","error":"TypeError: cajache.use is not a function"},{"fix":"Ensure the second argument is a function: `() => yourCode`.","cause":"Passing a non-function as second argument to `.use()`.","error":"TypeError: fnc is not a function"}],"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/Icaruk","github":"https://github.com/Icaruk/cajache","docs":null,"changelog":null,"pypi":null,"npm":"cajache","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"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}}