Registry / storage / simple-lru

simple-lru

JSON →
library0.0.3jsnpmunverified

A minimal Least Recently Used (LRU) cache implementation for Node.js and browsers. This package (v0.0.3) provides a simple constructor that accepts a maximum cache size and offers methods like set, get, peek, del, has, length, reset, keys, and a max getter/setter. It uses Object.create fallback for IE8 compatibility. The API is inspired by node-lru-cache but with a smaller footprint. No recent releases; appears unmaintained since 2013.

npm install simple-lru
INSTALL
IMPORT
SIG · SIMPLE-LRU
S
simple-lru
storagejavascriptv0.0.3
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.

SimpleLRU
import SimpleLRU from 'simple-lru'
var SimpleLRU = require('simple-lru').SimpleLRU
Default export is the constructor. CommonJS require should use require('simple-lru').default in ESM, but the package is CJS only.
SimpleLRU
const SimpleLRU = require('simple-lru')
const { SimpleLRU } = require('simple-lru')
CommonJS: module.exports = SimpleLRU directly, so destructuring is wrong.
SimpleLRU
var SimpleLRU = require('simple-lru');
import { SimpleLRU } from 'simple-lru'
Not a named export; ESM users must use default import (if using a bundler that supports default from CJS).

Creates an LRU cache with max 3 items, sets three values, retrieves 'a', then adds a fourth which evicts the least recently used item 'b'.

var SimpleLRU = require('simple-lru'); var cache = new SimpleLRU(3); cache.set('a', 'A'); cache.set('b', 'B'); cache.set('c', 'C'); console.log(cache.get('a')); // 'A' cache.set('d', 'D'); console.log(cache.get('a')); // 'A' console.log(cache.get('b')); // undefined (evicted) console.log(cache.keys()); // ['c', 'a', 'd']
Debug
Known issues
deprecatedPackage has not been updated since 2013 and may contain unpatched vulnerabilities.
fix
Use a maintained alternative like lru-cache or modern-lru.
affects: >=0.0.0
gotchaThe cache does not support TTL (time-to-live) eviction; only size-based eviction via LRU.
fix
If TTL needed, use a different library or implement manually.
affects: >=0.0.0
gotchaThe 'keys()' method returns keys in LRU order (least recently used first). This may be unexpected for users thinking it returns insertion order.
fix
Check documentation: most recently used key is last in the array.
affects: >=0.0.0
gotchaThe 'length()' method (function) returns number of items, not a property. This differs from arrays.
fix
Call length() as a function: cache.length() instead of cache.length.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: SimpleLRU is not a constructor
Using destructured import or require without the default export.
fix
Use const SimpleLRU = require('simple-lru'); (CommonJS) or import SimpleLRU from 'simple-lru' (ESM).
TypeError: cache.length is not a function
Treating length as a property instead of a method.
fix
Use cache.length() (call parentheses).
SimpleLRU is not defined
Package not installed or wrong import path.
fix
Run npm install simple-lru and ensure correct require/import.
Upgrade
Version history
0.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources
simple-lru — npm install simple-lru · libregistry