workbox-expiration
Advanced tools
Comparing version 5.0.0 to 5.1.0
"use strict"; | ||
// @ts-ignore | ||
try { | ||
self['workbox:expiration:5.0.0'] && _(); | ||
self['workbox:expiration:5.1.0'] && _(); | ||
} | ||
catch (e) { } |
@@ -6,3 +6,3 @@ this.workbox = this.workbox || {}; | ||
try { | ||
self['workbox:expiration:5.0.0'] && _(); | ||
self['workbox:expiration:5.1.0'] && _(); | ||
} catch (e) {} | ||
@@ -346,4 +346,2 @@ | ||
} | ||
return false; | ||
} else { | ||
@@ -434,3 +432,3 @@ const timestamp = await this._timestampModel.getTimestamp(url); | ||
let isFresh = this._isResponseDateFresh(cachedResponse); // Expire entries to ensure that even if the expiration date has | ||
const isFresh = this._isResponseDateFresh(cachedResponse); // Expire entries to ensure that even if the expiration date has | ||
// expired, it'll only be used once. | ||
@@ -437,0 +435,0 @@ |
@@ -1,2 +0,2 @@ | ||
this.workbox=this.workbox||{},this.workbox.expiration=function(t,s,e,i,a,n,h){"use strict";try{self["workbox:expiration:5.0.0"]&&_()}catch(t){}const r="workbox-expiration",c="cache-entries",o=t=>{const s=new URL(t,location.href);return s.hash="",s.href};class u{constructor(t){this.t=t,this.s=new i.DBWrapper(r,1,{onupgradeneeded:t=>this.i(t)})}i(t){const s=t.target.result.createObjectStore(c,{keyPath:"id"});s.createIndex("cacheName","cacheName",{unique:!1}),s.createIndex("timestamp","timestamp",{unique:!1}),a.deleteDatabase(this.t)}async setTimestamp(t,s){const e={url:t=o(t),timestamp:s,cacheName:this.t,id:this.h(t)};await this.s.put(c,e)}async getTimestamp(t){return(await this.s.get(c,this.h(t))).timestamp}async expireEntries(t,s){const e=await this.s.transaction(c,"readwrite",(e,i)=>{const a=e.objectStore(c).index("timestamp").openCursor(null,"prev"),n=[];let h=0;a.onsuccess=(()=>{const e=a.result;if(e){const i=e.value;i.cacheName===this.t&&(t&&i.timestamp<t||s&&h>=s?n.push(e.value):h++),e.continue()}else i(n)})}),i=[];for(const t of e)await this.s.delete(c,t.id),i.push(t.url);return i}h(t){return this.t+"|"+o(t)}}class w{constructor(t,s={}){this.o=!1,this.u=!1,this.l=s.maxEntries,this.m=s.maxAgeSeconds,this.t=t,this.p=new u(t)}async expireEntries(){if(this.o)return void(this.u=!0);this.o=!0;const t=this.m?Date.now()-1e3*this.m:0,e=await this.p.expireEntries(t,this.l),i=await self.caches.open(this.t);for(const t of e)await i.delete(t);this.o=!1,this.u&&(this.u=!1,s.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=w,t.ExpirationPlugin=class{constructor(t={}){this.cachedResponseWillBeUsed=(async({event:t,request:e,cacheName:i,cachedResponse:a})=>{if(!a)return null;let n=this.k(a);const h=this.D(i);s.dontWaitFor(h.expireEntries());const r=h.updateTimestamp(e.url);if(t)try{t.waitUntil(r)}catch(t){}return n?a:null}),this.cacheDidUpdate=(async({cacheName:t,request:s})=>{const e=this.D(t);await e.updateTimestamp(s.url),await e.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 e.WorkboxError("expire-custom-caches-only");let s=this.g.get(t);return s||(s=new w(t,this.N),this.g.set(t,s)),s}k(t){if(!this.m)return!0;const s=this._(t);return null===s||s>=Date.now()-1e3*this.m}_(t){if(!t.headers.has("date"))return null;const s=t.headers.get("date"),e=new Date(s).getTime();return isNaN(e)?null:e}async deleteCacheAndMetadata(){for(const[t,s]of this.g)await self.caches.delete(t),await s.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.0"]&&_()}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); | ||
//# sourceMappingURL=workbox-expiration.prod.js.map |
@@ -16,6 +16,6 @@ import './_version.js'; | ||
private _rerunRequested; | ||
private _maxEntries?; | ||
private _maxAgeSeconds?; | ||
private _cacheName; | ||
private _timestampModel; | ||
private readonly _maxEntries?; | ||
private readonly _maxAgeSeconds?; | ||
private readonly _cacheName; | ||
private readonly _timestampModel; | ||
/** | ||
@@ -22,0 +22,0 @@ * To construct a new CacheExpiration instance you must provide at least |
@@ -22,4 +22,4 @@ import { WorkboxPlugin } from 'workbox-core/types.js'; | ||
declare class ExpirationPlugin implements WorkboxPlugin { | ||
private _config; | ||
private _maxAgeSeconds?; | ||
private readonly _config; | ||
private readonly _maxAgeSeconds?; | ||
private _cacheExpirations; | ||
@@ -26,0 +26,0 @@ /** |
@@ -67,3 +67,3 @@ /* | ||
} | ||
let isFresh = this._isResponseDateFresh(cachedResponse); | ||
const isFresh = this._isResponseDateFresh(cachedResponse); | ||
// Expire entries to ensure that even if the expiration date has | ||
@@ -70,0 +70,0 @@ // expired, it'll only be used once. |
@@ -8,4 +8,4 @@ import '../_version.js'; | ||
declare class CacheTimestampsModel { | ||
private _cacheName; | ||
private _db; | ||
private readonly _cacheName; | ||
private readonly _db; | ||
/** | ||
@@ -12,0 +12,0 @@ * |
{ | ||
"name": "workbox-expiration", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"license": "MIT", | ||
@@ -30,5 +30,5 @@ "author": "Google's Web DevRel Team", | ||
"dependencies": { | ||
"workbox-core": "^5.0.0" | ||
"workbox-core": "^5.1.0" | ||
}, | ||
"gitHead": "571ffded1872309a305f108a99a5a36982fde342" | ||
"gitHead": "2a6b84b892b5c404671b898e926bf37b65d261da" | ||
} |
// @ts-ignore | ||
try{self['workbox:expiration:5.0.0']&&_()}catch(e){} | ||
try{self['workbox:expiration:5.1.0']&&_()}catch(e){} |
@@ -32,8 +32,8 @@ /* | ||
class CacheExpiration { | ||
private _isRunning: boolean = false; | ||
private _rerunRequested: boolean = false; | ||
private _maxEntries?: number; | ||
private _maxAgeSeconds?: number; | ||
private _cacheName: string; | ||
private _timestampModel: CacheTimestampsModel; | ||
private _isRunning = false; | ||
private _rerunRequested = false; | ||
private readonly _maxEntries?: number; | ||
private readonly _maxAgeSeconds?: number; | ||
private readonly _cacheName: string; | ||
private readonly _timestampModel: CacheTimestampsModel; | ||
@@ -184,3 +184,3 @@ /** | ||
const timestamp = await this._timestampModel.getTimestamp(url); | ||
const expireOlderThan = Date.now() - (this._maxAgeSeconds! * 1000); | ||
const expireOlderThan = Date.now() - (this._maxAgeSeconds * 1000); | ||
return (timestamp < expireOlderThan); | ||
@@ -187,0 +187,0 @@ } |
@@ -41,4 +41,4 @@ /* | ||
class ExpirationPlugin implements WorkboxPlugin { | ||
private _config: object; | ||
private _maxAgeSeconds?: number; | ||
private readonly _config: object; | ||
private readonly _maxAgeSeconds?: number; | ||
private _cacheExpirations: Map<string, CacheExpiration>; | ||
@@ -146,3 +146,3 @@ | ||
let isFresh = this._isResponseDateFresh(cachedResponse); | ||
const isFresh = this._isResponseDateFresh(cachedResponse); | ||
@@ -166,3 +166,3 @@ // Expire entries to ensure that even if the expiration date has | ||
`updating cache entry for ` + | ||
`'${getFriendlyURL((<FetchEvent> event).request.url)}'.`); | ||
`'${getFriendlyURL((event as FetchEvent).request.url)}'.`); | ||
} | ||
@@ -169,0 +169,0 @@ } |
@@ -38,4 +38,4 @@ /* | ||
class CacheTimestampsModel { | ||
private _cacheName: string; | ||
private _db: DBWrapper; | ||
private readonly _cacheName: string; | ||
private readonly _db: DBWrapper; | ||
@@ -64,3 +64,3 @@ /** | ||
private _handleUpgrade(event: IDBVersionChangeEvent) { | ||
const db = (<IDBOpenDBRequest> event.target).result; | ||
const db = (event.target as IDBOpenDBRequest).result; | ||
@@ -67,0 +67,0 @@ // TODO(philipwalton): EdgeHTML doesn't support arrays as a keyPath, so we |
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
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
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
243555
2046
Updatedworkbox-core@^5.1.0