Registry / storage / lru.min

lru.min

JSON →
library1.1.4jsnpmunverified

lru.min is a fast, efficient, and lightweight LRU (Least Recently Used) cache library for JavaScript. Current stable version is 1.1.4. It supports Node.js (>=8), Bun, Deno, and browsers with ES6+. Unlike other LRU caches, it offers high compatibility and performance comparable to popular alternatives. It ships TypeScript types and has a simple API with features like resize, peek, and eviction callbacks. Development is active with regular updates on GitHub.

npm install lru.min
INSTALL
IMPORT
SIG · LRU.MIN
L
lru.min
storagejavascriptv1.1.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createLRU
✓ import { createLRU } from 'lru.min'
✗ import createLRU from 'lru.min'
This is a named export. Default import will not work.
createLRU (CommonJS)
✓ const { createLRU } = require('lru.min')
✗ const createLRU = require('lru.min')
CommonJS require must destructure the named export.
Browser script
✓ <script src="https://cdn.jsdelivr.net/npm/lru.min@1.x.x/browser/lru.min.js"></script>
✗ <script src="https://cdn.jsdelivr.net/npm/lru.min@1.x.x/dist/lru.min.js"></script>
The browser build is in the 'browser' folder, not 'dist'.

Demonstrates creating an LRU cache with max size and eviction callback, setting and getting values, peeking, deleting, and clearing.

import { createLRU } from 'lru.min'; const max = 2; const onEviction = (key, value) => { console.log(`Key "${key}" with value "${value}" has been evicted.`); }; const LRU = createLRU({ max, onEviction }); LRU.set('A', 'My Value'); LRU.set('B', 'Other Value'); LRU.set('C', 'Another Value'); console.log(LRU.get('B')); LRU.delete('B'); console.log(LRU.peek('C')); LRU.clear(); console.log(LRU.size);
Debug
Known issues
gotchaThe option `onEviction` is spelled with 'i' not 'o' (not 'onEviction' as in some other libraries).
fix
Use `onEviction` (with 'i') when creating the cache.
affects: >=1.0.0
gotchaSetting a key with `undefined` is silently ignored; no error thrown.
fix
Avoid using `undefined` as a key; it will not be stored.
affects: >=1.0.0
gotchaThe method `evict(max)` is slower than `clear()`. Use `clear()` for removing all entries.
fix
Call `LRU.clear()` instead of `LRU.evict(LRU.size)` to clear all cache.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'lru.min' or its corresponding type declarations.
Missing package installation or TypeScript not configured to resolve node modules.
fix
Run `npm install lru.min` and ensure tsconfig.json has `"moduleResolution": "node"` or `"nodenext"`.
TypeError: lru_min_1.createLRU is not a function
Using default import instead of named import in ES modules.
fix
Change `import createLRU from 'lru.min'` to `import { createLRU } from 'lru.min'`.
ReferenceError: require is not defined
Using CommonJS `require` in an ES module context.
fix
Use `import { createLRU } from 'lru.min'` or switch to CommonJS by setting `"type": "commonjs"` in package.json.
Upgrade
Version history
1.1.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
lru.min — npm install lru.min · libregistry