An LRU cache implementation that is API-compatible with ES6 Map, allowing drop-in replacement for caching with limited memory usage. Version 2.1.0 is current, with stable releases via npm. It supports Node.js >=12 and ships TypeScript type definitions. Unlike many LRU caches, MapLRU mimics the Map interface exactly, enabling use of standard methods like set, get, has, delete, clear, keys, values, entries, and forEach. It also adds extra methods: peek (retrieve without marking as used), last (last accessed key), and keysAccessed (ordered keys). It is lightweight, has no dependencies, and is licensed under Unlicense.
npm install map-lruNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic LRU cache operations: instantiation, set/get, automatic eviction, last accessed key, peek, delete, clear.
Always pass a positive integer to new MapLRU(maxSize).
Use cache.keysAccessed() to iterate keys in order of most recently used (last is the most recent).
Check cache.size > 0 before accessing cache.last.
Use import MapLRU from 'map-lru' for ESM, or const MapLRU = require('map-lru') for CJS.const MapLRU = require('map-lru');Ensure you use new MapLRU(maxSize) after import.
Use [...cache.entries()] or [...cache.keys()].
No dependency data recorded yet.