A caching library for Web Extensions (Chrome, Firefox, Safari) with support for expired cache clearing. Version 6.0.3 is the latest stable release, actively maintained by the author (fregante). It provides two main APIs: CachedValue for simple get/set operations, and CachedFunction for memoizing function calls automatically. The library requires the `storage` permission and optionally `alarms` for scheduled cache purging. It ships TypeScript types and works with both Manifest v2 and v3. The deprecated legacy API from v5 is still available via `webext-storage-cache/legacy.js`. Key differentiators from general Node.js caching libraries: it is specifically designed for browser extensions, uses `chrome.storage` under the hood, and handles cross-context caching (background, content scripts, popup).
npm install webext-storage-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic usage of CachedValue: check cache, fetch data, store, and retrieve.
Migrate to CachedValue or CachedFunction. See https://github.com/fregante/webext-storage-cache/releases/v6.0.0
Switch to ESM imports (import { ... } from 'webext-storage-cache') or use dynamic import().Use import cache from 'webext-storage-cache/legacy.js' to access legacy API, or migrate to new API.
Add 'alarms' permission to manifest.json and import the module in the background script.
Use unique keys with prefixing for each context (e.g., 'content:myKey' vs 'background:myKey').
Ensure you are running the code inside a Web Extension (background, content script, popup) and have 'storage' permission in manifest.json.
Use import { CachedValue } from 'webext-storage-cache' instead of import CachedValue from 'webext-storage-cache'.Add 'alarms' to permissions in manifest.json and ensure the module is imported in the background script.