Cache values in your Web Extension and clear them on expiration. Also includes a memoize-like API to cache any function results automatically
MIT License
Bot releases are hidden (Show)
CachedValue
and CachedFunction
(#41) 5255795The API has changed to improve type safety and extend the capabilities of cache.function
.
You can use the legacy API for a gradual migration, but you should start using the new functions before the next major version.
// v5
await cache.set('user-id', 510, {days: 2});
const id = await cache.get('user-id');
// v6
const idCache = new CachedValue('user-id', {maxAge: {days: 2}});
await idCache.set(510);
const id = await idCache.get();
// v5
const cachedGetHTML = cache.function(getHTML, {
cacheKey: args => args.join(','),
maxAge: {days: 2},
});
const html = await cachedGetHTML('info.html');
// v6
const cache = new CachedFunction('html', {
maxAge: {days: 2},
);
const html = await cache.get('info.html');
https://github.com/fregante/webext-storage-cache/compare/v5.1.1...v6.0.0
https://github.com/fregante/webext-storage-cache/compare/v5.1.0...v5.1.1
https://github.com/fregante/webext-storage-cache/compare/v5.0.1...v5.1.0
https://github.com/fregante/webext-storage-cache/compare/v5.0.0...v5.0.1
It should not bring any breaking changes, but I released it as a major version for safety. The minimum browser version probably increased slightly due to the "es2020" TypeScript output.
cache.set(x, undefined)
to delete the cached item (#26) c7a1e23https://github.com/fregante/webext-storage-cache/compare/v4.2.0...v5.0.0
cache.function
so it doesn't get called multiple times (#28) 59790adhttps://github.com/fregante/webext-storage-cache/compare/v4.1.1...v4.2.0
https://github.com/fregante/webext-storage-cache/compare/v4.1.0...v4.1.1
chrome.alarms
to purge cache where available (#23) a2c38a0It's not required, but to use this you'll have to include alarms
as a permission. This does not appear to the user.
has()
and function()
(#22) d61d250https://github.com/fregante/webext-storage-cache/compare/v4.0.0...v4.1.0
cache.clear()
method: 2936f2d405f84fe3e7b875d837705e3b1c156870webextStorageCache
global: 9f64562426ada0fd5bfc832c8bb044d9d178e80ecache.set
return the value itself: 54af212199238b1c3fc3d0d8f3337bfea3d00961cache.function
method: #5tsd
: 44f82499a73fc2ba045e20b348faf860dcc615c7