
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
lru-cache-idb
Advanced tools
A least-recently-used (LRU) cache for web applications based on IndexedDB.
A least-recently-used (LRU) cache for web applications, based on IndexedDB.
IndexedDB providing in-browser persistence for web applications is an obvious tool for use as a cache. On the other hand, using browser storage for caching leads to specific challenges, such as the fact that multiple instances of a web site (open in multiple tabs, for instance) all access the same storage.
Design:
Demo: https://cnoelle.github.io/lru-cache-idb/
Install: npm install lru-cache-idb
Basic usage:
import { createCacheIdb } from "lru-cache-idb";
const cache = createCacheIdb({maxItems: 1000, memoryConfig: {maxItemsInMemory: 100}});
await cache.set("entry1", {a: 1, description: "The first entry"});
await cache.set("entry2", {a: 2, description: "The 2nd entry"});
const obj = await cache.get("entry1");
console.log("Object found:", obj);
It is possible to instantiate multiple caches on one page, but the database names must differ:
const cache = createCacheIdb({database: "MySpecialDb", maxItems: 1000, memoryConfig: {maxItemsInMemory: 100}});
This is the database name in IndexedDB, the default being "LruIdbItemsCache". The existing databases/caches on a page can be viewed in the browser developer console, e.g. under Web Storage->Indexed DB (Firefox) or Application->Storage->IndexedDB (Chrome).
API documentation: https://cnoelle.github.io/lru-cache-idb/docs/index.html
After cloning the repository, install the dev dependencies: npm install.
npm run build
This repository contains a sample HTML file index.html using the library. For instance, start a dev server using npx http-server, then the page will be available in the browser at http://localhost:8080 (check port in console output). Build first, index.html refers to the compiled Javascript files in the dist/ folder. The demo app can also be found at https://cnoelle.github.io/lru-cache-idb/.
Tests run in NodeJS and hence cannot access an actual browser's IndexedDB implementation. Instead, they run against fake-indexeddb. To run all tests, build first, then:
npm run test
To run tests in a single file:
npx ava ./test/testDefaultCache.js
In order to run a single test in a single file, replace test("...", async t => { at the beginning of the test by test.only("...", async t => {.
Documentation is generated using typedoc. Run
npm run docs
and find the updated documentation in the docs subfolder.
FAQs
A least-recently-used (LRU) cache for web applications based on IndexedDB.
The npm package lru-cache-idb receives a total of 1,160 weekly downloads. As such, lru-cache-idb popularity was classified as popular.
We found that lru-cache-idb demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.