Registry / storage / blru
library0.1.8jsnpmunverified

blru is a lightweight LRU cache library for Node.js, version 0.1.8. It provides a simple and efficient implementation of a Least Recently Used cache. The library is designed for Node.js environments (>=8.0.0) and is commonly used as a dependency in the bcoin ecosystem. It offers basic operations like get, set, del, and has, with configurable maximum size. Compared to other caching libraries like lru-cache, blru focuses on minimalism and stability, though it has limited recent maintenance.

npm install blru
INSTALL
IMPORT
SIG · BLRU
B
blru
storagejavascriptv0.1.8
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
const blru = require('blru');
import blru from 'blru';
Package is CommonJS-only; ESM import will fail unless using a bundler or Node's ESM compat.
LRU
const blru = require('blru'); const cache = new blru();
const { LRU } = require('blru');
The default export is the constructor function; there is no named export.
no symbol (type import)
// TypeScript: const blru = require('blru'); const cache = new blru(); // or with @types/blru if available
import blru, { LRU } from 'blru';
No type definitions included; use @types/blru (third-party) or declare module manually.

Demonstrates creating an LRU cache with max size, basic operations (set, get, has, del), and iteration over entries.

const blru = require('blru'); const cache = new blru(100); // max 100 items // Set values cache.set('key1', 'value1'); cache.set('key2', 'value2'); // Get values const val = cache.get('key1'); console.log(val); // 'value1' // Check existence if (cache.has('key2')) { console.log('key2 exists'); } // Delete a key cache.del('key2'); // Iterate (order from most recent to least recent) for (const [key, value] of cache) { console.log(key, value); }
Debug
Known issues
gotchaThe max size must be an integer; passing 0 or a non-number silently fails or creates an unbounded cache.
fix
Always pass a positive integer to the constructor (e.g., new blru(100)).
affects: *
gotchaIteration order is from most recent to least recent, not insertion order like Map.
fix
Use a standard for...of loop; be aware that the order differs from Map.
affects: *
gotchaThe library is CommonJS-only; using ESM imports (import blru from 'blru') will fail unless you configure a bundler or use .mjs with createRequire.
fix
Use require('blru') or wrap in a CommonJS module.
affects: *
gotchaNo type definitions shipped; TypeScript users will get 'any' or need @types/blru.
fix
Install @types/blru if available, or create a declaration file.
affects: *
Errors
Common errors & fixes
TypeError: Class constructor blru cannot be invoked without 'new'
Forgetting 'new' when creating a cache instance.
fix
Use new blru(max) instead of blru(max).
Cannot find module 'blru'
Package not installed or incorrect require path.
fix
Run npm install blru and ensure require('blru') is correct.
import blru from 'blru'; SyntaxError: Cannot use import statement outside a module
Using ESM import in a CommonJS context without proper package.json configuration.
fix
Switch to const blru = require('blru'); or enable ESM in your project.
Upgrade
Version history
0.1.8latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
44 hits · last 30 days
node
38
Resources
packageblru
blru — npm install blru · libregistry