
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@digitalbazaar/lru-memoize
Advanced tools
A Memoized wrapper around the JavaScript
lru-cachelibrary.
lru-memoize is used to
to memoize promises
(as opposed to just the results of the operations),
which helps in high-concurrency use cases. (And in turn, it uses
lru-cache under the hood.)
To install locally (for development):
git clone https://github.com/digitalbazaar/lru-memoize.git
cd lru-memoize
npm install
To import:
import { LruCache } from '@digitalbazaar/lru-memoize';
// or
const { LruCache } = require('@digitalbazaar/lru-memoize');
The memoized LruCache constructor passes any options given to it through to
the lru-cache constructor, so see that repo for the full list of cache
management options. Commonly used ones include:
max (default: 100) - maximum size of the cache.maxAge (default: 5 sec/5000 ms) - maximum age of an item in ms.updateAgeOnGet (default: false) - When using time-expiring entries with
maxAge, setting this to true will make each entry's effective time update to
the current time whenever it is retrieved from cache, thereby extending the
expiration date of the entry.This library is useful for caching (in a deterministic memoized fashion) expensive or long-running functions, such as API requests, database lookups, and so on.
For example, say you have a function fetchStatus() that retrieves a result from a web API (here, simulated with a
delay() wait). To cache the result of this function:
import { LruCache } from '@digitalbazaar/lru-memoize';
// Cache expiration/TTL: 5 seconds
const myCache = new LruCache({ maxAge: 5000 });
async function fetchStatus() {
// simulate an async task
await delay(100);
executedTestFn = true;
return {success: true, timestamp: Date.now()};
}
// Load the cached result if it's present, otherwise, perform the operation
const result = await myCache.memoize({
key: 'myApiResults',
fn: fetchStatus
});
// You can also memoize a particular call to a function, using anonymous arrow functions:
const url = 'https://api.example';
const result = await myCache.memoize({
key: 'myResults',
fn: async () => fetchMyResultsFromWeb({ url })
});
The key param is used to namespace the caches, in case the same LruCache instance is being used to cache different
types of operations/functions.
PRs accepted.
If editing the Readme, please conform to the standard-readme specification.
FAQs
LRU Memoize
We found that @digitalbazaar/lru-memoize demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.