Registry / storage / lru-queue

lru-queue

JSON →
library0.1.0jsnpmunverified

lru-queue is a low-level LRU (Least Recently Used) queue implementation originally derived from the memoizee package. Current stable version is 0.1.0. It provides a size-limited queue with hit, delete, and clear operations. It is used internally by memoizee for cache size limiting. The package is minimal, production-driven, with no dependencies and a focus on Node.js and browser usage via bundlers. Release cadence is low as it is stable and small. It differentiates by being a simple, focused utility rather than a full cache solution.

npm install lru-queue
INSTALL
IMPORT
SIG · LRU-QUEUE
L
lru-queue
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.

default
var lruQueue = require('lru-queue');
import lruQueue from 'lru-queue';
Package uses CJS and does not have a default ESM export. Use require for compatibility.
hit
queue.hit('id');
Method to register a hit for an id. Returns the evicted id if the queue is full, undefined otherwise.
delete
queue.delete('id');
Deletes an id from the queue. Note: delete is a reserved word in some contexts but works in JS.

Demonstrates the three methods: hit, delete, and clear on an LRU queue with a limit of 3.

var lruQueue = require('lru-queue'); var queue = lruQueue(3); // limit to 3 items queue.hit('raz'); // size: 1 queue.hit('dwa'); // size: 2 queue.hit('trzy'); // size: 3 queue.hit('cztery'); // returns 'trzy', replaces oldest queue.delete('raz'); // size: 2 queue.clear(); // size: 0
Debug
Known issues
gotchaThe package is CJS-only; using an ESM import may break in bundlers expecting ESM.
fix
Use require or configure bundler to handle CJS.
affects: >=0.0.0
gotchaThe hit method returns the evicted id only when the queue is full; otherwise returns undefined.
fix
Check the return value, but do not rely on it always being defined.
affects: >=0.0.0
gotchaThe delete method has the same name as the JavaScript reserved word 'delete', which can cause issues in strict mode or certain environments.
fix
Use bracket notation or call it as a method on the queue object (it is safe in most modern JS environments).
affects: >=0.0.0
deprecatedPackage is in maintenance mode; no new features are expected. Consider using full cache libraries like lru-cache for more functionality.
fix
Switch to a more feature-rich LRU library if additional functionality is needed.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: lruQueue is not a function
Importing the package as a default ES module import (import lruQueue from 'lru-queue') in a Node.js environment expecting CJS.
fix
Use require: var lruQueue = require('lru-queue');
Cannot find module 'lru-queue'
Package not installed or incorrect import path.
fix
Run 'npm install lru-queue' and ensure the import is correct.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
25 hits · last 30 days
node
24
Resources
lru-queue — npm install lru-queue · libregistry