Package Exports
- webext-storage-cache
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (webext-storage-cache) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
webext-storage-cache
WebExtensions module: Map-like promised cache storage with expiration. Chrome and Firefox.
This module works on content scripts, background pages and option pages.
Install
You can just download the standalone bundle (it might take a minute to download) and include the file in your manifest.json
, or:
npm install --save webext-storage-cache
import storageCache from 'webext-storage-cache';
const storageCache = require('webext-storage-cache');
Usage
This module requires the storage
permission:
// manifest.json
{
"permissions": [
"storage"
]
}
import cache from 'webext-storage-cache';
(async () => {
if (!await cache.has('unique')) {
const cachableItem = await someFunction();
await cache.set('unique', cachableItem, 3 /* days */);
}
console.log(await cache.get('unique'));
})();
API
Similar to a Map()
, but all methods a return a Promise
.
cache.has(key)
Checks if the given key is in the cache, returns a boolean
.
key
Type: string
cache.get(key)
Returns the cached value of key if it exists and hasn't expired, returns undefined
otherwise.
key
Type: string
cache.set(key, value, expiration /* in days */)
Caches the given key and value for a given amount of days.
key
Type: string
value
Type: string | number | boolean
or array | object
of those three types
expiration
The number of days after which the cache item will expire.
Type: number
Default: 30
cache.delete(key)
Deletes the requested item from the cache.
key
Type: string
Related
- webext-options-sync - Helps you manage and autosave your extension's options.
- webext-domain-permission-toggle - Browser-action context menu to request permission for the current tab.
- webext-dynamic-content-scripts - Automatically inject your
content_scripts
on custom domains. - webext-detect-page - Detects where the current browser extension code is being run.
- webext-content-script-ping - One-file interface to detect whether your content script have loaded.
Awesome WebExtensions
: A curated list of awesome resources for Web Extensions development.
License
MIT © Federico Brigante — Twitter, Connor Love