Registry / storage / lru-map-like

lru-map-like

JSON →
library2.0.0jsnpmunverified

A lightweight LRU cache implementation with a Map-like interface that supports non-string keys including objects. Version 2.0.0 is the current stable release. The package is tiny (~2KB gzipped) compared to alternatives like node-lru-cache (~10KB gzipped). It prioritizes minimal bundle size while providing essential cache features with strong TypeScript support. Releases are infrequent.

npm install lru-map-like
INSTALL
IMPORT
SIG · LRU-MAP-LIKE
L
lru-map-like
storagejavascriptv2.0.0
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.

LRUMapLike
import { LRUMapLike } from 'lru-map-like'
const LRUMapLike = require('lru-map-like')
ESM is recommended, but CJS is also supported. When using CJS with require(), the exported value is an object with the LRUMapLike property. Do not use default import.
LRUMapLike (TypeScript type annotation)
import type { LRUMapLike } from 'lru-map-like'
import { LRUMapLike } from 'lru-map-like' // value import may be unnecessary if only used as type
TypeScript types are shipped. Use 'import type' for type-only imports.

Shows how to create an LRU cache, add entries, retrieve them, and see eviction when exceeding limit.

import { LRUMapLike } from 'lru-map-like'; const cache = new LRUMapLike(3); cache.set('key1', 'value1'); cache.set('key2', 'value2'); cache.set('key3', 'value3'); cache.get('key1'); // 'value1' cache.set('key4', 'value4'); // evicts oldest: 'key2' cache.has('key2'); // false console.log(cache.values()); // ['value3', 'value1', 'value4']
Debug
Known issues
gotchaLRUMapLike constructor expects a number (max limit). Do not pass options object; any other argument type may cause unexpected behavior.
fix
new LRUMapLike(100)
affects: >=1.0.0
gotchaThe get() method returns undefined for missing keys, but also for keys with value undefined. Use has() to check existence explicitly.
fix
if (cache.has(key)) { const val = cache.get(key); }
affects: >=1.0.0
deprecatedThe onDispose method is deprecated in v2. Use options in constructor (forthcoming) instead.
fix
Remove onDispose calls and prepare for options-based disposal.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'lru-map-like'
Package is not installed or typo in package name.
fix
npm install lru-map-like
LRUMapLike is not a constructor
Using default import instead of named import.
fix
import { LRUMapLike } from 'lru-map-like'
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
14
Resources
lru-map-like — npm install lru-map-like · libregistry