workbox-expiration
Advanced tools
Comparing version 5.1.3 to 6.0.0-alpha.0
@@ -219,2 +219,4 @@ this.workbox = this.workbox || {}; | ||
* it's treated as stale and removed. | ||
* @param {Object} [config.matchOptions] The [`CacheQueryOptions`](https://developer.mozilla.org/en-US/docs/Web/API/Cache/delete#Parameters) | ||
* that will be used when calling `delete()` on the cache. | ||
*/ | ||
@@ -247,3 +249,3 @@ constructor(cacheName, config = {}) { | ||
paramName: 'config.maxEntries' | ||
}); // TODO: Assert is positive | ||
}); | ||
} | ||
@@ -257,3 +259,3 @@ | ||
paramName: 'config.maxAgeSeconds' | ||
}); // TODO: Assert is positive | ||
}); | ||
} | ||
@@ -264,2 +266,3 @@ } | ||
this._maxAgeSeconds = config.maxAgeSeconds; | ||
this._matchOptions = config.matchOptions; | ||
this._cacheName = cacheName; | ||
@@ -286,3 +289,3 @@ this._timestampModel = new CacheTimestampsModel(cacheName); | ||
for (const url of urlsExpired) { | ||
await cache.delete(url); | ||
await cache.delete(url, this._matchOptions); | ||
} | ||
@@ -379,7 +382,12 @@ | ||
/** | ||
* This plugin can be used in the Workbox APIs to regularly enforce a | ||
* This plugin can be used in a `workbox-strategy` to regularly enforce a | ||
* limit on the age and / or the number of cached requests. | ||
* | ||
* It can only be used with `workbox-strategy` instances that have a | ||
* [custom `cacheName` property set](/web/tools/workbox/guides/configure-workbox#custom_cache_names_in_strategies). | ||
* In other words, it can't be used to expire entries in strategy that uses the | ||
* default runtime cache name. | ||
* | ||
* Whenever a cached request is used or updated, this plugin will look | ||
* at the used Cache and remove any old or extra requests. | ||
* at the associated cache and remove any old or extra requests. | ||
* | ||
@@ -405,2 +413,4 @@ * When using `maxAgeSeconds`, requests may be used *once* after expiring | ||
* it's treated as stale and removed. | ||
* @param {Object} [config.matchOptions] The [`CacheQueryOptions`](https://developer.mozilla.org/en-US/docs/Web/API/Cache/delete#Parameters) | ||
* that will be used when calling `delete()` on the cache. | ||
* @param {boolean} [config.purgeOnQuotaError] Whether to opt this cache in to | ||
@@ -407,0 +417,0 @@ * automatic deletion if the available storage quota has been exceeded. |
@@ -1,2 +0,2 @@ | ||
this.workbox=this.workbox||{},this.workbox.expiration=function(t,e,s,i,a,n,h){"use strict";try{self["workbox:expiration:5.1.3"]&&_()}catch(t){}const r=t=>{const e=new URL(t,location.href);return e.hash="",e.href};class c{constructor(t){this.t=t,this.s=new i.DBWrapper("workbox-expiration",1,{onupgradeneeded:t=>this.i(t)})}i(t){const e=t.target.result.createObjectStore("cache-entries",{keyPath:"id"});e.createIndex("cacheName","cacheName",{unique:!1}),e.createIndex("timestamp","timestamp",{unique:!1}),a.deleteDatabase(this.t)}async setTimestamp(t,e){const s={url:t=r(t),timestamp:e,cacheName:this.t,id:this.h(t)};await this.s.put("cache-entries",s)}async getTimestamp(t){return(await this.s.get("cache-entries",this.h(t))).timestamp}async expireEntries(t,e){const s=await this.s.transaction("cache-entries","readwrite",(s,i)=>{const a=s.objectStore("cache-entries").index("timestamp").openCursor(null,"prev"),n=[];let h=0;a.onsuccess=()=>{const s=a.result;if(s){const i=s.value;i.cacheName===this.t&&(t&&i.timestamp<t||e&&h>=e?n.push(s.value):h++),s.continue()}else i(n)}}),i=[];for(const t of s)await this.s.delete("cache-entries",t.id),i.push(t.url);return i}h(t){return this.t+"|"+r(t)}}class o{constructor(t,e={}){this.o=!1,this.u=!1,this.l=e.maxEntries,this.m=e.maxAgeSeconds,this.t=t,this.p=new c(t)}async expireEntries(){if(this.o)return void(this.u=!0);this.o=!0;const t=this.m?Date.now()-1e3*this.m:0,s=await this.p.expireEntries(t,this.l),i=await self.caches.open(this.t);for(const t of s)await i.delete(t);this.o=!1,this.u&&(this.u=!1,e.dontWaitFor(this.expireEntries()))}async updateTimestamp(t){await this.p.setTimestamp(t,Date.now())}async isURLExpired(t){if(this.m){return await this.p.getTimestamp(t)<Date.now()-1e3*this.m}return!1}async delete(){this.u=!1,await this.p.expireEntries(1/0)}}return t.CacheExpiration=o,t.ExpirationPlugin=class{constructor(t={}){this.cachedResponseWillBeUsed=async({event:t,request:s,cacheName:i,cachedResponse:a})=>{if(!a)return null;const n=this.k(a),h=this.D(i);e.dontWaitFor(h.expireEntries());const r=h.updateTimestamp(s.url);if(t)try{t.waitUntil(r)}catch(t){}return n?a:null},this.cacheDidUpdate=async({cacheName:t,request:e})=>{const s=this.D(t);await s.updateTimestamp(e.url),await s.expireEntries()},this.N=t,this.m=t.maxAgeSeconds,this.g=new Map,t.purgeOnQuotaError&&h.registerQuotaErrorCallback(()=>this.deleteCacheAndMetadata())}D(t){if(t===n.cacheNames.getRuntimeName())throw new s.WorkboxError("expire-custom-caches-only");let e=this.g.get(t);return e||(e=new o(t,this.N),this.g.set(t,e)),e}k(t){if(!this.m)return!0;const e=this._(t);return null===e||e>=Date.now()-1e3*this.m}_(t){if(!t.headers.has("date"))return null;const e=t.headers.get("date"),s=new Date(e).getTime();return isNaN(s)?null:s}async deleteCacheAndMetadata(){for(const[t,e]of this.g)await self.caches.delete(t),await e.delete();this.g=new Map}},t}({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core); | ||
this.workbox=this.workbox||{},this.workbox.expiration=function(t,e,s,i,a,n,h){"use strict";try{self["workbox:expiration:5.1.3"]&&_()}catch(t){}const r=t=>{const e=new URL(t,location.href);return e.hash="",e.href};class c{constructor(t){this.t=t,this.s=new i.DBWrapper("workbox-expiration",1,{onupgradeneeded:t=>this.i(t)})}i(t){const e=t.target.result.createObjectStore("cache-entries",{keyPath:"id"});e.createIndex("cacheName","cacheName",{unique:!1}),e.createIndex("timestamp","timestamp",{unique:!1}),a.deleteDatabase(this.t)}async setTimestamp(t,e){const s={url:t=r(t),timestamp:e,cacheName:this.t,id:this.h(t)};await this.s.put("cache-entries",s)}async getTimestamp(t){return(await this.s.get("cache-entries",this.h(t))).timestamp}async expireEntries(t,e){const s=await this.s.transaction("cache-entries","readwrite",(s,i)=>{const a=s.objectStore("cache-entries").index("timestamp").openCursor(null,"prev"),n=[];let h=0;a.onsuccess=()=>{const s=a.result;if(s){const i=s.value;i.cacheName===this.t&&(t&&i.timestamp<t||e&&h>=e?n.push(s.value):h++),s.continue()}else i(n)}}),i=[];for(const t of s)await this.s.delete("cache-entries",t.id),i.push(t.url);return i}h(t){return this.t+"|"+r(t)}}class o{constructor(t,e={}){this.o=!1,this.u=!1,this.l=e.maxEntries,this.m=e.maxAgeSeconds,this.p=e.matchOptions,this.t=t,this.k=new c(t)}async expireEntries(){if(this.o)return void(this.u=!0);this.o=!0;const t=this.m?Date.now()-1e3*this.m:0,s=await this.k.expireEntries(t,this.l),i=await self.caches.open(this.t);for(const t of s)await i.delete(t,this.p);this.o=!1,this.u&&(this.u=!1,e.dontWaitFor(this.expireEntries()))}async updateTimestamp(t){await this.k.setTimestamp(t,Date.now())}async isURLExpired(t){if(this.m){return await this.k.getTimestamp(t)<Date.now()-1e3*this.m}return!1}async delete(){this.u=!1,await this.k.expireEntries(1/0)}}return t.CacheExpiration=o,t.ExpirationPlugin=class{constructor(t={}){this.cachedResponseWillBeUsed=async({event:t,request:s,cacheName:i,cachedResponse:a})=>{if(!a)return null;const n=this.D(a),h=this.N(i);e.dontWaitFor(h.expireEntries());const r=h.updateTimestamp(s.url);if(t)try{t.waitUntil(r)}catch(t){}return n?a:null},this.cacheDidUpdate=async({cacheName:t,request:e})=>{const s=this.N(t);await s.updateTimestamp(e.url),await s.expireEntries()},this.g=t,this.m=t.maxAgeSeconds,this._=new Map,t.purgeOnQuotaError&&h.registerQuotaErrorCallback(()=>this.deleteCacheAndMetadata())}N(t){if(t===n.cacheNames.getRuntimeName())throw new s.WorkboxError("expire-custom-caches-only");let e=this._.get(t);return e||(e=new o(t,this.g),this._.set(t,e)),e}D(t){if(!this.m)return!0;const e=this.q(t);return null===e||e>=Date.now()-1e3*this.m}q(t){if(!t.headers.has("date"))return null;const e=t.headers.get("date"),s=new Date(e).getTime();return isNaN(s)?null:s}async deleteCacheAndMetadata(){for(const[t,e]of this._)await self.caches.delete(t),await e.delete();this._=new Map}},t}({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core); | ||
//# sourceMappingURL=workbox-expiration.prod.js.map |
@@ -5,2 +5,3 @@ import './_version.js'; | ||
maxAgeSeconds?: number; | ||
matchOptions?: CacheQueryOptions; | ||
} | ||
@@ -19,2 +20,3 @@ /** | ||
private readonly _maxAgeSeconds?; | ||
private readonly _matchOptions?; | ||
private readonly _cacheName; | ||
@@ -32,2 +34,4 @@ private readonly _timestampModel; | ||
* it's treated as stale and removed. | ||
* @param {Object} [config.matchOptions] The [`CacheQueryOptions`](https://developer.mozilla.org/en-US/docs/Web/API/Cache/delete#Parameters) | ||
* that will be used when calling `delete()` on the cache. | ||
*/ | ||
@@ -34,0 +38,0 @@ constructor(cacheName: string, config?: CacheExpirationConfig); |
@@ -32,2 +32,4 @@ /* | ||
* it's treated as stale and removed. | ||
* @param {Object} [config.matchOptions] The [`CacheQueryOptions`](https://developer.mozilla.org/en-US/docs/Web/API/Cache/delete#Parameters) | ||
* that will be used when calling `delete()` on the cache. | ||
*/ | ||
@@ -58,3 +60,2 @@ constructor(cacheName, config = {}) { | ||
}); | ||
// TODO: Assert is positive | ||
} | ||
@@ -68,3 +69,2 @@ if (config.maxAgeSeconds) { | ||
}); | ||
// TODO: Assert is positive | ||
} | ||
@@ -74,2 +74,3 @@ } | ||
this._maxAgeSeconds = config.maxAgeSeconds; | ||
this._matchOptions = config.matchOptions; | ||
this._cacheName = cacheName; | ||
@@ -93,3 +94,3 @@ this._timestampModel = new CacheTimestampsModel(cacheName); | ||
for (const url of urlsExpired) { | ||
await cache.delete(url); | ||
await cache.delete(url, this._matchOptions); | ||
} | ||
@@ -96,0 +97,0 @@ if (process.env.NODE_ENV !== 'production') { |
import { WorkboxPlugin } from 'workbox-core/types.js'; | ||
import './_version.js'; | ||
/** | ||
* This plugin can be used in the Workbox APIs to regularly enforce a | ||
* This plugin can be used in a `workbox-strategy` to regularly enforce a | ||
* limit on the age and / or the number of cached requests. | ||
* | ||
* It can only be used with `workbox-strategy` instances that have a | ||
* [custom `cacheName` property set](/web/tools/workbox/guides/configure-workbox#custom_cache_names_in_strategies). | ||
* In other words, it can't be used to expire entries in strategy that uses the | ||
* default runtime cache name. | ||
* | ||
* Whenever a cached request is used or updated, this plugin will look | ||
* at the used Cache and remove any old or extra requests. | ||
* at the associated cache and remove any old or extra requests. | ||
* | ||
@@ -31,2 +36,4 @@ * When using `maxAgeSeconds`, requests may be used *once* after expiring | ||
* it's treated as stale and removed. | ||
* @param {Object} [config.matchOptions] The [`CacheQueryOptions`](https://developer.mozilla.org/en-US/docs/Web/API/Cache/delete#Parameters) | ||
* that will be used when calling `delete()` on the cache. | ||
* @param {boolean} [config.purgeOnQuotaError] Whether to opt this cache in to | ||
@@ -38,2 +45,3 @@ * automatic deletion if the available storage quota has been exceeded. | ||
maxAgeSeconds?: number; | ||
matchOptions?: CacheQueryOptions; | ||
purgeOnQuotaError?: boolean; | ||
@@ -40,0 +48,0 @@ }); |
@@ -18,7 +18,12 @@ /* | ||
/** | ||
* This plugin can be used in the Workbox APIs to regularly enforce a | ||
* This plugin can be used in a `workbox-strategy` to regularly enforce a | ||
* limit on the age and / or the number of cached requests. | ||
* | ||
* It can only be used with `workbox-strategy` instances that have a | ||
* [custom `cacheName` property set](/web/tools/workbox/guides/configure-workbox#custom_cache_names_in_strategies). | ||
* In other words, it can't be used to expire entries in strategy that uses the | ||
* default runtime cache name. | ||
* | ||
* Whenever a cached request is used or updated, this plugin will look | ||
* at the used Cache and remove any old or extra requests. | ||
* at the associated cache and remove any old or extra requests. | ||
* | ||
@@ -43,2 +48,4 @@ * When using `maxAgeSeconds`, requests may be used *once* after expiring | ||
* it's treated as stale and removed. | ||
* @param {Object} [config.matchOptions] The [`CacheQueryOptions`](https://developer.mozilla.org/en-US/docs/Web/API/Cache/delete#Parameters) | ||
* that will be used when calling `delete()` on the cache. | ||
* @param {boolean} [config.purgeOnQuotaError] Whether to opt this cache in to | ||
@@ -45,0 +52,0 @@ * automatic deletion if the available storage quota has been exceeded. |
{ | ||
"name": "workbox-expiration", | ||
"version": "5.1.3", | ||
"version": "6.0.0-alpha.0", | ||
"license": "MIT", | ||
@@ -17,10 +17,5 @@ "author": "Google's Web DevRel Team", | ||
], | ||
"scripts": { | ||
"build": "gulp build-packages --package workbox-expiration", | ||
"version": "npm run build", | ||
"prepare": "npm run build" | ||
}, | ||
"workbox": { | ||
"browserNamespace": "workbox.expiration", | ||
"packageType": "browser" | ||
"packageType": "sw" | ||
}, | ||
@@ -31,5 +26,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"workbox-core": "^5.1.3" | ||
"workbox-core": "^6.0.0-alpha.0" | ||
}, | ||
"gitHead": "fe4399505e02c3af6515fc8ffae8c58791f43f3c" | ||
"gitHead": "3dfe1f4c5ed450bc4b7420321f1a113ff4382d1b" | ||
} |
@@ -22,2 +22,3 @@ /* | ||
maxAgeSeconds?: number; | ||
matchOptions?: CacheQueryOptions; | ||
} | ||
@@ -37,2 +38,3 @@ | ||
private readonly _maxAgeSeconds?: number; | ||
private readonly _matchOptions?: CacheQueryOptions; | ||
private readonly _cacheName: string; | ||
@@ -51,2 +53,4 @@ private readonly _timestampModel: CacheTimestampsModel; | ||
* it's treated as stale and removed. | ||
* @param {Object} [config.matchOptions] The [`CacheQueryOptions`](https://developer.mozilla.org/en-US/docs/Web/API/Cache/delete#Parameters) | ||
* that will be used when calling `delete()` on the cache. | ||
*/ | ||
@@ -77,4 +81,2 @@ constructor(cacheName: string, config: CacheExpirationConfig = {}) { | ||
}); | ||
// TODO: Assert is positive | ||
} | ||
@@ -89,4 +91,2 @@ | ||
}); | ||
// TODO: Assert is positive | ||
} | ||
@@ -97,2 +97,3 @@ } | ||
this._maxAgeSeconds = config.maxAgeSeconds; | ||
this._matchOptions = config.matchOptions; | ||
this._cacheName = cacheName; | ||
@@ -121,3 +122,3 @@ this._timestampModel = new CacheTimestampsModel(cacheName); | ||
for (const url of urlsExpired) { | ||
await cache.delete(url); | ||
await cache.delete(url, this._matchOptions); | ||
} | ||
@@ -124,0 +125,0 @@ |
@@ -23,7 +23,12 @@ /* | ||
/** | ||
* This plugin can be used in the Workbox APIs to regularly enforce a | ||
* This plugin can be used in a `workbox-strategy` to regularly enforce a | ||
* limit on the age and / or the number of cached requests. | ||
* | ||
* It can only be used with `workbox-strategy` instances that have a | ||
* [custom `cacheName` property set](/web/tools/workbox/guides/configure-workbox#custom_cache_names_in_strategies). | ||
* In other words, it can't be used to expire entries in strategy that uses the | ||
* default runtime cache name. | ||
* | ||
* Whenever a cached request is used or updated, this plugin will look | ||
* at the used Cache and remove any old or extra requests. | ||
* at the associated cache and remove any old or extra requests. | ||
* | ||
@@ -52,2 +57,4 @@ * When using `maxAgeSeconds`, requests may be used *once* after expiring | ||
* it's treated as stale and removed. | ||
* @param {Object} [config.matchOptions] The [`CacheQueryOptions`](https://developer.mozilla.org/en-US/docs/Web/API/Cache/delete#Parameters) | ||
* that will be used when calling `delete()` on the cache. | ||
* @param {boolean} [config.purgeOnQuotaError] Whether to opt this cache in to | ||
@@ -59,2 +66,3 @@ * automatic deletion if the available storage quota has been exceeded. | ||
maxAgeSeconds?: number; | ||
matchOptions?: CacheQueryOptions; | ||
purgeOnQuotaError?: boolean; | ||
@@ -61,0 +69,0 @@ } = {}) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
260799
2087
1
+ Addedworkbox-core@6.6.1(transitive)
- Removedworkbox-core@5.1.4(transitive)
Updatedworkbox-core@^6.0.0-alpha.0