Cache-LRU is a minimal JavaScript library that provides an in-memory key-indexed cache with Least-Recently-Used (LRU) purging strategy. Current stable version is 1.2.0, released on 2025-01-27. Unlike many LRU caches (e.g., lru-cache, node-lru-cache), Cache-LRU guarantees strict O(1) time complexity for all main operations (get, set, has, del, touch, peek) including internal LRU reordering, making it suitable for performance-critical applications. It supports optional per-item expiration and a disposal callback. The library is small (≈300 lines), has zero dependencies, and works in both Node.js and browser environments. It exports a single class via CommonJS. No TypeScript types are bundled.
npm install cache-lruNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a cache with a limit, stores and retrieves items, demonstrates O(1) operations including touch, peek, has, and disposal callback.
Use `if (cache.has(key)) cache.del(key);` or wrap in try-catch.
Always call `has()` before `touch()` or use try-catch.
`const max = cache.limit();` works; but note that passing `undefined` does NOT change the limit.
Use `cache.set('key', value, 5000);` for 5 seconds.Manually call `cache.get(key)` to trigger expiration, or use a separate periodic sweep.
Use CommonJS require: `const CacheLRU = require('cache-lru');`.Check existence first with `has()` or wrap in try-catch.
Run `npm install cache-lru`. For browser, use a bundler like webpack or browserify, or include dist/cache-lru.js via <script> tag.
No dependency data recorded yet.