Installations
npm install webext-storage-cache
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
>=18
Node Version
22.3.0
NPM Version
10.8.1
Score
71.2
Supply Chain
99.5
Quality
77.8
Maintenance
100
Vulnerability
99.6
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (55.94%)
TypeScript (44.06%)
Developer
Download Statistics
Total Downloads
112,910
Last Day
58
Last Week
301
Last Month
1,757
Last Year
39,513
GitHub Statistics
81 Stars
101 Commits
4 Forks
4 Watching
3 Branches
4 Contributors
Sponsor this package
Package Meta Information
Latest Version
6.0.3
Package Id
webext-storage-cache@6.0.3
Unpacked Size
18.10 kB
Size
5.98 kB
File Count
11
NPM Version
10.8.1
Node Version
22.3.0
Publised On
01 Jul 2024
Total Downloads
Cumulative downloads
Total Downloads
112,910
Last day
-71.6%
58
Compared to previous day
Last week
-71%
301
Compared to previous week
Last month
-63.7%
1,757
Compared to previous month
Last year
201.8%
39,513
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
webext-storage-cache
Cache values in your Web Extension and clear them on expiration. Also includes a memoize-like API to cache any function results automatically.
- Browsers: Chrome, Firefox, and Safari
- Manifest: v2 and v3
- Context: They can be called from any context that has access to the
chrome.storage
APIs - Permissions: (with attached "reasons" for submission to the Chrome Web Store)
storage
: "The extension caches some values into the local storage"alarms
: "The extension automatically clears its expired storage at certain intervals"
Install
You can download the standalone bundle and include it in your manifest.json
.
Or use npm
:
1npm install webext-storage-cache
Usage
This module requires the storage
permission and it’s suggested to also use alarms
to safely schedule cache purging:
1/* manifest.json */ 2{ 3 "permissions": [ 4 "storage", 5 "alarms" 6 ], 7 "background": { 8 "scripts": [ 9 /* Remember to include/import it in the background to enable expired cache purging */ 10 "webext-storage-cache.js" 11 ] 12 } 13}
1import {CachedValue} from 'webext-storage-cache'; 2 3const item = new CachedValue('unique', { 4 maxAge: { 5 days: 3, 6 }, 7}); 8 9(async () => { 10 if (!(await item.isCached())) { 11 const cachableItem = await someFunction(); 12 await item.set(cachableItem); 13 } 14 15 console.log(await item.get()); 16})();
The same code could also be written more effectively with CachedFunction
:
1import {CachedFunction} from 'webext-storage-cache'; 2 3const cachedFunction = new CachedFunction('unique', { 4 updater: someFunction, 5 maxAge: { 6 days: 3, 7 }, 8}); 9 10(async () => { 11 console.log(await cachedFunction()); 12})();
API
- CachedValue - A simple API getter/setter
- CachedFunction - A memoize-like API to cache your function calls without manually calling
isCached
/get
/set
globalCache
- Global helpers, documented belowlegacy
- The previous Map-like API, documented below, deprecated
globalCache.clear()
Clears the cache. This is a special method that acts on the entire cache of the extension.
1import {globalCache} from 'webext-storage-cache'; 2 3document.querySelector('.options .clear-cache').addEventListener('click', async () => { 4 await globalCache.clear() 5})
legacy API
The API used until v5 has been deprecated and you should migrate to:
CachedValue
for simplecache.get
/cache.set
calls. This API makes more sense in a typed context because the type is preserved/enforced across calls.CachedFunction
forcache.function
. It behaves in a similar fashion, but it also has extra methods likegetCached
andgetFresh
You can:
- Migrate from v5 to v6, or
- Keep using the legacy API (except
cache.function
) by importingwebext-storage-cache/legacy.js
(until v7 is published)
1import cache from "webext-storage-cache/legacy.js"; 2 3await cache.get('my-url'); 4await cache.set('my-url', 'https://example.com');
The documentation for the legacy API can be found on the v5 version of this readme.
Related
- webext-detect - Detects where the current browser extension code is being run.
- webext-options-sync - Helps you manage and autosave your extension's options.
- webext-base-css - Extremely minimal stylesheet/setup for Web Extensions’ options pages (also dark mode)
- webext-dynamic-content-scripts - Automatically registers your content_scripts on domains added via permission.request
- More…
License
MIT © Federico Brigante
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
0 existing vulnerabilities detected
Reason
2 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 4
Reason
Found 2/30 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:49: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:50: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:37: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/esm-lint.yml:59: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/esm-lint.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/esm-lint.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/esm-lint.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/esm-lint.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/esm-lint.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/esm-lint.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/esm-lint.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/esm-lint.yml:67: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/esm-lint.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/esm-lint.yml:76: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/esm-lint.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/esm-lint.yml:85: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/esm-lint.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/esm-lint.yml:98: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/esm-lint.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/esm-lint.yml:99: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/esm-lint.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/esm-lint.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/esm-lint.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/esm-lint.yml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/fregante/webext-storage-cache/esm-lint.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:17
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:29
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:43
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:55
- Warn: npmCommand not pinned by hash: .github/workflows/esm-lint.yml:69
- Warn: npmCommand not pinned by hash: .github/workflows/esm-lint.yml:80
- Warn: npmCommand not pinned by hash: .github/workflows/esm-lint.yml:88
- Warn: npmCommand not pinned by hash: .github/workflows/esm-lint.yml:22
- Warn: npmCommand not pinned by hash: .github/workflows/esm-lint.yml:40
- Warn: npmCommand not pinned by hash: .github/workflows/esm-lint.yml:49
- Warn: npmCommand not pinned by hash: .github/workflows/esm-lint.yml:61
- Warn: npmCommand not pinned by hash: .github/workflows/esm-lint.yml:104
- Info: 0 out of 19 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 12 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Warn: no topLevel permission defined: .github/workflows/esm-lint.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 14 are checked with a SAST tool
Score
3.8
/10
Last Scanned on 2025-01-06
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More