Registry / storage / lru-map-cache

lru-map-cache

JSON →
library0.1.0jsnpmunverified

A lightweight LRU cache implementation leveraging the native Map class for ordered iteration. Version 0.1.0 is stable with no recent updates. Differentiators: simple API, no dependencies, O(1) operations by exploiting Map's insertion order. Best for Node.js or browser projects needing a minimal LRU cache without additional features like TTL or serialization. Not recommended for high-concurrency or memory-sensitive environments.

npm install lru-map-cache
INSTALL
IMPORT
SIG · LRU-MAP-CACHE
L
lru-map-cache
storagejavascriptv0.1.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.

LRUCache
import LRUCache from 'lru-map-cache'
const LRUCache = require('lru-map-cache')
Package uses default export but does not provide TypeScript types.
LRUCache (CommonJS)
const LRUCache = require('lru-map-cache')
const { LRUCache } = require('lru-map-cache')
Named export does not exist in CommonJS; use default.
LRUCache (TypeScript)
import LRUCache from 'lru-map-cache'
No type definitions included; consider @types/lru-map-cache or declare module manually.

Demonstrates creating an LRU cache with capacity 3, adding four items, and showing eviction of the least recently used key.

import LRUCache from 'lru-map-cache'; const cache = new LRUCache(3); cache.set('a', 1); cache.set('b', 2); cache.set('c', 3); cache.set('d', 4); console.log(cache.get('a')); // undefined console.log(cache.get('b')); // 2 console.log(cache.size()); // 3
Debug
Known issues
gotchaConstructor expects an integer capacity; passing undefined, null, or 0 may cause unexpected behavior (e.g., negative capacity if type coercion occurs).
fix
Always pass a positive integer to new LRUCache(capacity).
affects: >=0.1.0
deprecatedThe package has not been updated in over 2 years. Consider using more maintained alternatives like 'lru-cache' for bug fixes and features.
fix
Migrate to 'lru-cache' package which offers TTL, events, and TypeScript support.
affects: >=0.1.0
gotchaCache does not expose a 'delete' method that returns boolean; always deletes silently.
fix
Use cache.has(key) before delete if you need to check existence.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: LRUCache is not a constructor
Using require('lru-map-cache') returns an ES module default export which cannot be called with new.
fix
Use import LRUCache from 'lru-map-cache' or const LRUCache = require('lru-map-cache').default
ReferenceError: LRUCache is not defined
Missing import or require statement.
fix
Add import LRUCache from 'lru-map-cache' at top of file.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

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