A minimal O(1) LRU cache for Node.js supporting set, get, peek, remove, clear, and eviction events. Version 3.1.0 is stable and suitable for small caches. It uses a linked list and hash map for O(1) operations. Differentiators: simple API, evict event, optional maxAge for TTL, and CommonJS support. No TypeScript types, no ESM. Suitable for Node >= 0.4.0.
npm install lruNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates an LRU cache with max 2 items, listens for evict event, and demonstrates set/get/remove/clear.
Access `cache.length` directly, not `cache.length()`.
Check return value for existence: const val = cache.remove(key); if (val !== undefined) { ... }Manually emit evict events before clear if needed.
Set `maxAge` in milliseconds.
Use `peek` if you want to check without marking as recently used.
Create own `.d.ts` or use `@types/lru` if available.
Pass options object with `max` and optionally `maxAge`.
Use `const LRU = require('lru');`Use `cache.length` without parentheses.
Ensure `const LRU = require('lru');` is present.Create a new LRU instance first: `const cache = new LRU(10);`
No dependency data recorded yet.