Registry / database / xache
library1.2.1jsnpmunverified

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.

npm install xache
INSTALL
IMPORT
SIG · XACHE
X
xache
databasejavascriptv1.2.1
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.

Xache
✓ import Xache from 'xache'
ESM default import, works in Node 14+ with ESM or bundlers.
Xache
✓ const Xache = require('xache')
CommonJS require, compatible with Node 6+.

Creates a cache with max 5 entries and 1 second expiry, demonstrates set/get, auto-expiry, and eviction on overflow.

import Xache from 'xache'; const cache = new Xache({ maxSize: 5, maxAge: 1000 // 1 second }); cache.set('key1', 'value1'); console.log(cache.get('key1')); // 'value1' // Wait 1.5 seconds setTimeout(() => { console.log(cache.get('key1')); // undefined (expired) }, 1500); // Overfill cache cache.set('a', 1); cache.set('b', 2); cache.set('c', 3); cache.set('d', 4); cache.set('e', 5); cache.set('f', 6); // 'a' is evicted console.log(cache.has('a')); // false
Debug
Known issues
gotchamaxSize and maxAge are approximate; the cache removes oldest entries but does not guarantee immediate cleanup after expiry.
fix
Do not rely on precise timing; use for short-lived cache needs only.
affects: >=0.0.0
gotchaNo built-in way to get cache stats (e.g., number of evictions).
fix
Implement custom tracking via createMap or subclass.
affects: >=0.0.0
gotchaOnly handles string keys; custom createMap may allow other types but not recommended.
fix
Use strings for keys; coerce other types if necessary.
affects: >=0.0.0
gotchacreateMap function is called per cache instance; ensure it returns a fresh Map-like object with Map interface.
fix
Use () => new Map() or return an object with .get, .set, .delete, .has, .clear, [Symbol.iterator], .size.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'xache'
Package not installed
fix
Run 'npm install xache' in your project root.
TypeError: cache.get is not a function
Importing incorrectly (e.g., destructuring Xache as non-default).
fix
Use 'const Xache = require('xache')' for CommonJS or 'import Xache from 'xache' for ESM.
TypeError: createMap is not a function
Passing an object instead of a function for createMap option.
fix
Pass a function that returns a Map, e.g., createMap: () => new Map()
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
packagexache ↗
xache — npm install xache · libregistry