An LRU cache that evicts least-recently-used items when full. Current version 1.0.3, stable with low release cadence. Fork of Mnemonist's LRUCache with added eviction event emission via nanoevents. Differentiator: emits 'evicted' event on eviction, unlike Mnemonist. Pure ESM package, requires Node >=14 or modern browser.
npm install least-recentNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates an LRU cache with capacity 3, adds entries, demonstrates get and eviction event listener.
Ensure your project is ESM or use dynamic import() for CommonJS.
Monitor releases; consider forking if event behavior is essential.
Always pass a positive integer capacity.
Handle eviction only once per set() and not on explicit removal.
Use a transpiler/bundler that provides Map polyfill if targeting very old environments.
Use import { LRUCache } from 'least-recent' instead of require.Convert to ES module ("type": "module" in package.json) or use dynamic import()Ensure you installed version 1.0.0+ and are calling on('evicted', callback).Pass a positive integer (e.g., new LRUCache(1000)).