Registry / storage / lru-cache-ext

lru-cache-ext

JSON →
library5.0.1jsnpmunverified

Thin wrapper around lru-cache (v5.0.1) adding memoize and memoizeSync functions. Latest version as of writing. Release cadence follows semantic-release. Differentiates from plain lru-cache by providing built-in memoization with cache-on-null control, suitable for Node.js >=20.

npm install lru-cache-ext
INSTALL
IMPORT
SIG · LRU-CACHE-EXT
L
lru-cache-ext
storagejavascriptv5.0.1
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
import LRU from 'lru-cache-ext'
const LRU = require('lru-cache-ext')
Package is ESM-only for Node >=20.
memoize
import { memoize } from 'lru-cache-ext'
import memoize from 'lru-cache-ext'
memoize is a named export, not default.
memoizeSync
import { memoizeSync } from 'lru-cache-ext'
Named export for synchronous memoization.

Demonstrates creating a cache instance, async memoize, sync memoize, and cacheNull option.

import LRU, { memoize, memoizeSync } from 'lru-cache-ext'; const cache = new LRU({ max: 100, maxAge: 1000 * 60 * 5 }); // memoize async example function fetchData(id) { return new Promise(resolve => { setTimeout(() => resolve(`Data for ${id}`), 100); }); } async function test() { const result1 = await memoize('key1', () => fetchData(1)); console.log(result1); // 'Data for 1' const result2 = await memoize('key1', () => fetchData(2)); // returns cached console.log(result2); // 'Data for 1' } test(); // memoizeSync example function expensiveSync(key) { return key.toUpperCase(); } const syncResult = memoizeSync('syncKey', () => expensiveSync('hello')); console.log(syncResult); // 'HELLO' // cacheNull option const cacheNoNull = new LRU({ max: 10, cacheNull: false }); memoize('nullKey', () => null).then(val => console.log(val)); // null is not cached
Debug
Known issues
breakingVersion 5.x drops CommonJS support; requires Node >=20 and ESM imports.
fix
Use import syntax and ensure Node >=20.
affects: >=5.0.0
deprecatedThe 'cacheNull' option defaults to true, which may lead to unexpected caching of null values.
fix
Explicitly set cacheNull: false if you don't want to cache null results from memoize.
affects: >=1.0.0
gotchamemoizeSync does not invalidate cache on async errors thrown in valueFn if valueFn returns a promise that rejects.
fix
For async functions, prefer memoize (async) to ensure cache invalidation on error.
affects: >=1.0.0
gotchalru-cache-ext re-exports all functionality of lru-cache, so options and methods are identical; do not confuse with lru-cache's import name.
fix
Import directly from 'lru-cache-ext' and refer to lru-cache docs for options and methods.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/lru-cache-ext/index.js from ... not supported.
Using CommonJS require() with an ESM-only package.
fix
Switch to ES module import syntax or use dynamic import().
TypeError: LRU is not a constructor
Using default import as a constructor but the default export is the extended LRU class? Actually the default export is the class itself. This error could occur if you imported the wrong thing.
fix
Ensure you are using: import LRU from 'lru-cache-ext'
Upgrade
Version history
5.0.1latest on npm
Audit
Dependencies
lru-cacherequiredCore caching functionality; lru-cache-ext wraps it.
Agent activity
13 hits · last 30 days
node
12
Amazon
1
Resources
lru-cache-ext — npm install lru-cache-ext · libregistry