{"id":46825,"library":"xache","title":"xache","description":"xache is a minimal auto-expiring, max-size cache for Node.js and browsers. Current stable version is 1.2.1, with infrequent releases focused on bug fixes. It provides a simple Map-like API with configurable maxSize and maxAge, removing oldest entries when the size limit is hit. Unlike more complex caches (e.g., node-cache or lru-cache), xache is extremely lightweight, has zero dependencies, and supports custom backing stores via a createMap option. It is ideal for scenarios requiring a no-frills in-memory cache with automatic expiry and size limits.","status":"active","version":"1.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/mafintosh/xache","tags":["javascript"],"install":[{"cmd":"npm install xache","lang":"bash","label":"npm"},{"cmd":"yarn add xache","lang":"bash","label":"yarn"},{"cmd":"pnpm add xache","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM default import, works in Node 14+ with ESM or bundlers.","symbol":"Xache","correct":"import Xache from 'xache'"},{"note":"CommonJS require, compatible with Node 6+.","symbol":"Xache","correct":"const Xache = require('xache')"}],"quickstart":{"code":"import Xache from 'xache';\n\nconst cache = new Xache({\n  maxSize: 5,\n  maxAge: 1000 // 1 second\n});\n\ncache.set('key1', 'value1');\nconsole.log(cache.get('key1')); // 'value1'\n\n// Wait 1.5 seconds\nsetTimeout(() => {\n  console.log(cache.get('key1')); // undefined (expired)\n}, 1500);\n\n// Overfill cache\ncache.set('a', 1);\ncache.set('b', 2);\ncache.set('c', 3);\ncache.set('d', 4);\ncache.set('e', 5);\ncache.set('f', 6); // 'a' is evicted\nconsole.log(cache.has('a')); // false\n","lang":"typescript","description":"Creates a cache with max 5 entries and 1 second expiry, demonstrates set/get, auto-expiry, and eviction on overflow."},"warnings":[{"fix":"Do not rely on precise timing; use for short-lived cache needs only.","message":"maxSize and maxAge are approximate; the cache removes oldest entries but does not guarantee immediate cleanup after expiry.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Implement custom tracking via createMap or subclass.","message":"No built-in way to get cache stats (e.g., number of evictions).","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use strings for keys; coerce other types if necessary.","message":"Only handles string keys; custom createMap may allow other types but not recommended.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use () => new Map() or return an object with .get, .set, .delete, .has, .clear, [Symbol.iterator], .size.","message":"createMap function is called per cache instance; ensure it returns a fresh Map-like object with Map interface.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'1.2.1':21 'api':36 'auto':7 'auto-expir':6 'automat':94 'back':73 'browser':16 'bug':27 'cach':12,54,58,62,92 'complex':53 'configur':38 'createmap':77 'current':17 'custom':72 'depend':69 'e.g':55 'entri':44 'expir':8 'expiri':95 'extrem':65 'fix':28 'focus':25 'frill':88 'hit':50 'ideal':81 'in-memori':89 'infrequ':23 'javascript':99 'lightweight':66 'like':35 'limit':48,98 'lru':61 'lru-cach':60 'map':34 'map-lik':33 'max':10 'max-siz':9 'maxag':41 'maxsiz':39 'memori':91 'minim':5 'no-fril':86 'node':57 'node-cach':56 'node.js':14 'oldest':43 'option':78 'provid':30 'releas':24 'remov':42 'requir':84 'scenario':83 'simpl':32 'size':11,47,97 'stabl':18 'store':74 'support':71 'unlik':51 'version':19 'via':75 'xach':1,2,63 'zero':68","created_at":"2026-06-07T13:01:48.837716+00:00","updated_at":"2026-06-07T13:01:48.837716+00:00","problems":[{"fix":"Run 'npm install xache' in your project root.","cause":"Package not installed","error":"Cannot find module 'xache'"},{"fix":"Use 'const Xache = require('xache')' for CommonJS or 'import Xache from 'xache' for ESM.","cause":"Importing incorrectly (e.g., destructuring Xache as non-default).","error":"TypeError: cache.get is not a function"},{"fix":"Pass a function that returns a Map, e.g., createMap: () => new Map()","cause":"Passing an object instead of a function for createMap option.","error":"TypeError: createMap 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/mafintosh/xache","github":"https://github.com/mafintosh/xache","docs":null,"changelog":null,"pypi":null,"npm":"xache","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"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}}