A minimal least-recently-used (LRU) cache implementation in about 35 lines of code, extending the native Map class. At version 1.1.0 (latest), it supports configurable max size, per-item or global maxAge for expiration, and a stale option to return expired values before deletion. Released steadily since 2017, it has zero dependencies and ships TypeScript type declarations. Compared to heavier alternatives like lru-cache, tmp-cache prioritizes simplicity and small bundle size, making it suitable for lightweight caching in Node.js (>=6) or modern browsers.
npm install tmp-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic LRU cache creation with max size, get, set, size, has, and expiration with stale mode.
To set other options like maxAge, always pass an object: `new Cache({ max: 5, maxAge: 1000 })`.Call `cache.get(key, false)` to retrieve without refreshing expiry.
Do not rely on the cache to free memory automatically; call `delete` or `clear` explicitly if needed.
Pass `undefined` or omit the third argument to use the default maxAge.
No action needed.
Use `import Cache from 'tmp-cache'` for ES modules, or `const Cache = require('tmp-cache')` for CommonJS.Run `npm install tmp-cache` and ensure tsconfig.json includes `"moduleResolution": "node"`.
Ensure maxAge is a number (milliseconds) or undefined. Example: `cache.set('key', value, 1000)`.No dependency data recorded yet.