{"id":46796,"library":"webext-storage-cache","title":"webext-storage-cache","description":"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).","status":"active","version":"6.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/fregante/webext-storage-cache","tags":["javascript","await","background page","browser","cache","chrome","content script","expirating","extension","typescript"],"install":[{"cmd":"npm install webext-storage-cache","lang":"bash","label":"npm"},{"cmd":"yarn add webext-storage-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add webext-storage-cache","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for cross-browser compatibility with `chrome.storage` and `chrome.alarms`","package":"webextension-polyfill","optional":true}],"imports":[{"note":"CachedValue is a named export, not default.","wrong":"import CachedValue from 'webext-storage-cache'","symbol":"CachedValue","correct":"import { CachedValue } from 'webext-storage-cache'"},{"note":"ESM-only package; require() will not work.","wrong":"const CachedFunction = require('webext-storage-cache').CachedFunction","symbol":"CachedFunction","correct":"import { CachedFunction } from 'webext-storage-cache'"},{"note":"globalCache is a named export, not default. Subpath imports are not valid.","wrong":"import globalCache from 'webext-storage-cache/global'","symbol":"globalCache","correct":"import { globalCache } from 'webext-storage-cache'"}],"quickstart":{"code":"// manifest.json must include permissions: [\"storage\", \"alarms\"]\nimport { CachedValue } from 'webext-storage-cache';\n\nasync function main() {\n  const cache = new CachedValue('myKey', { maxAge: { hours: 1 } });\n  if (!(await cache.isCached())) {\n    const data = await fetchDataFromApi();\n    await cache.set(data);\n  }\n  const result = await cache.get();\n  console.log(result);\n}\n\nmain();","lang":"typescript","description":"Shows basic usage of CachedValue: check cache, fetch data, store, and retrieve."},"warnings":[{"fix":"Migrate to CachedValue or CachedFunction. See https://github.com/fregante/webext-storage-cache/releases/v6.0.0","message":"The legacy API (cache.get, cache.set) from v5 is deprecated and will be removed in v7. Use CachedValue or CachedFunction instead.","severity":"deprecated","affected_versions":">=6.0.0"},{"fix":"Switch to ESM imports (import { ... } from 'webext-storage-cache') or use dynamic import().","message":"In v6, the package became ESM-only. CommonJS require() will not work.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Use import cache from 'webext-storage-cache/legacy.js' to access legacy API, or migrate to new API.","message":"In v6, the legacy API is moved to 'webext-storage-cache/legacy.js'. The main export no longer includes cache.get/cache.set.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Add 'alarms' permission to manifest.json and import the module in the background script.","message":"CachedFunction requires the 'alarms' permission for scheduled cache purging; otherwise, expired items may not be cleared until the extension restarts.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Use unique keys with prefixing for each context (e.g., 'content:myKey' vs 'background:myKey').","message":"CachedValue and CachedFunction must be instantiated with a unique key per cache entry. Using the same key across different contexts (e.g., content script and background page) may cause conflicts.","severity":"gotcha","affected_versions":">=6.0.0"}],"env_vars":null,"search_vec":"'/legacy.js':89 '6.0.3':21 'activ':27 'alarm':58 'api':37,78 'author':31 'automat':49 'avail':83 'await':120 'background':115,121 'browser':102,123 'cach':4,6,18,61,88,95,114,124 'cachedfunct':44 'cachedvalu':38 'call':48 'chrome':11,125 'chrome.storage':105 'clear':19 'content':116,126 'context':113 'cross':112 'cross-context':111 'deprec':76 'design':100 'differenti':91 'expir':17,128 'extens':10,103,129 'firefox':12 'fregant':32 'function':47 'general':93 'get/set':41 'handl':110 'hood':108 'javascript':119 'key':90 'latest':24 'legaci':77 'librari':7,51,96 'main':36 'maintain':28 'manifest':71 'memoiz':46 'node.js':94 'oper':42 'option':57 'page':122 'permiss':55 'popup':118 'provid':34 'purg':62 'releas':26 'requir':52 'safari':13 'schedul':60 'script':117,127 'ship':64 'simpl':40 'specif':99 'stabl':25 'still':82 'storag':3,54,87 'support':15 'two':35 'type':66 'typescript':65,130 'use':104 'v2':72 'v3':74 'v5':80 'version':20 'via':84 'web':9 'webext':2,86 'webext-storage-cach':1,85 'work':68","created_at":"2026-06-07T13:01:41.046119+00:00","updated_at":"2026-06-07T13:01:41.046119+00:00","problems":[{"fix":"Ensure you are running the code inside a Web Extension (background, content script, popup) and have 'storage' permission in manifest.json.","cause":"Running code in a context where chrome.storage is not available (e.g., Node.js, or missing permissions).","error":"TypeError: Cannot read properties of undefined (reading 'storage')"},{"fix":"Use import { CachedValue } from 'webext-storage-cache' instead of import CachedValue from 'webext-storage-cache'.","cause":"Trying to use a default import when the package only has named exports.","error":"Uncaught SyntaxError: The requested module 'webext-storage-cache' does not provide an export named 'default'"},{"fix":"Add 'alarms' to permissions in manifest.json and ensure the module is imported in the background script.","cause":"Missing alarms permission in manifest.json.","error":"Error: The 'alarms' permission is required to schedule cache purging. Add 'alarms' to your manifest permissions and import the module in the background script."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/fregante/webext-storage-cache#readme","github":"https://github.com/fregante/webext-storage-cache","docs":null,"changelog":null,"pypi":null,"npm":"webext-storage-cache","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}