workbox-expiration
Advanced tools
Comparing version 6.3.0 to 6.4.0
"use strict"; | ||
// @ts-ignore | ||
try { | ||
self['workbox:expiration:6.2.4'] && _(); | ||
self['workbox:expiration:6.3.0'] && _(); | ||
} | ||
catch (e) { } |
@@ -294,3 +294,3 @@ this.workbox = this.workbox || {}; | ||
try { | ||
self['workbox:expiration:6.2.4'] && _(); | ||
self['workbox:expiration:6.3.0'] && _(); | ||
} catch (e) {} | ||
@@ -489,6 +489,6 @@ | ||
/** | ||
* Returns an open connection to the database. | ||
* | ||
* @private | ||
*/ | ||
* Returns an open connection to the database. | ||
* | ||
* @private | ||
*/ | ||
@@ -495,0 +495,0 @@ |
@@ -1,2 +0,2 @@ | ||
this.workbox=this.workbox||{},this.workbox.expiration=function(t,e,n,s,i){"use strict";function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t}).apply(this,arguments)}let a,o;const c=new WeakMap,u=new WeakMap,h=new WeakMap,f=new WeakMap,l=new WeakMap;let d={get(t,e,n){if(t instanceof IDBTransaction){if("done"===e)return u.get(t);if("objectStoreNames"===e)return t.objectStoreNames||h.get(t);if("store"===e)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return D(t[e])},set:(t,e,n)=>(t[e]=n,!0),has:(t,e)=>t instanceof IDBTransaction&&("done"===e||"store"===e)||e in t};function w(t){return t!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(o||(o=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(t)?function(...e){return t.apply(m(this),e),D(c.get(this))}:function(...e){return D(t.apply(m(this),e))}:function(e,...n){const s=t.call(m(this),e,...n);return h.set(s,e.sort?e.sort():[e]),D(s)}}function p(t){return"function"==typeof t?w(t):(t instanceof IDBTransaction&&function(t){if(u.has(t))return;const e=new Promise(((e,n)=>{const s=()=>{t.removeEventListener("complete",i),t.removeEventListener("error",r),t.removeEventListener("abort",r)},i=()=>{e(),s()},r=()=>{n(t.error||new DOMException("AbortError","AbortError")),s()};t.addEventListener("complete",i),t.addEventListener("error",r),t.addEventListener("abort",r)}));u.set(t,e)}(t),e=t,(a||(a=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])).some((t=>e instanceof t))?new Proxy(t,d):t);var e}function D(t){if(t instanceof IDBRequest)return function(t){const e=new Promise(((e,n)=>{const s=()=>{t.removeEventListener("success",i),t.removeEventListener("error",r)},i=()=>{e(D(t.result)),s()},r=()=>{n(t.error),s()};t.addEventListener("success",i),t.addEventListener("error",r)}));return e.then((e=>{e instanceof IDBCursor&&c.set(e,t)})).catch((()=>{})),l.set(e,t),e}(t);if(f.has(t))return f.get(t);const e=p(t);return e!==t&&(f.set(t,e),l.set(e,t)),e}const m=t=>l.get(t);const b=["get","getKey","getAll","getAllKeys","count"],y=["put","add","delete","clear"],I=new Map;function B(t,e){if(!(t instanceof IDBDatabase)||e in t||"string"!=typeof e)return;if(I.get(e))return I.get(e);const n=e.replace(/FromIndex$/,""),s=e!==n,i=y.includes(n);if(!(n in(s?IDBIndex:IDBObjectStore).prototype)||!i&&!b.includes(n))return;const r=async function(t,...e){const r=this.transaction(t,i?"readwrite":"readonly");let a=r.store;return s&&(a=a.index(e.shift())),(await Promise.all([a[n](...e),i&&r.done]))[0]};return I.set(e,r),r}d=(t=>r({},t,{get:(e,n,s)=>B(e,n)||t.get(e,n,s),has:(e,n)=>!!B(e,n)||t.has(e,n)}))(d);try{self["workbox:expiration:6.2.4"]&&_()}catch(t){}const g="cache-entries",x=t=>{const e=new URL(t,location.href);return e.hash="",e.href};class k{constructor(t){this.t=null,this.M=t}i(t){const e=t.createObjectStore(g,{keyPath:"id"});e.createIndex("cacheName","cacheName",{unique:!1}),e.createIndex("timestamp","timestamp",{unique:!1})}N(t){this.i(t),this.M&&function(t,{blocked:e}={}){const n=indexedDB.deleteDatabase(t);e&&n.addEventListener("blocked",(()=>e())),D(n).then((()=>{}))}(this.M)}async setTimestamp(t,e){const n={url:t=x(t),timestamp:e,cacheName:this.M,id:this.T(t)},s=(await this.getDb()).transaction(g,"readwrite",{durability:"relaxed"});await s.store.put(n),await s.done}async getTimestamp(t){const e=await this.getDb(),n=await e.get(g,this.T(t));return null==n?void 0:n.timestamp}async expireEntries(t,e){const n=await this.getDb();let s=await n.transaction(g).store.index("timestamp").openCursor(null,"prev");const i=[];let r=0;for(;s;){const n=s.value;n.cacheName===this.M&&(t&&n.timestamp<t||e&&r>=e?i.push(s.value):r++),s=await s.continue()}const a=[];for(const t of i)await n.delete(g,t.id),a.push(t.url);return a}T(t){return this.M+"|"+x(t)}async getDb(){return this.t||(this.t=await function(t,e,{blocked:n,upgrade:s,blocking:i,terminated:r}={}){const a=indexedDB.open(t,e),o=D(a);return s&&a.addEventListener("upgradeneeded",(t=>{s(D(a.result),t.oldVersion,t.newVersion,D(a.transaction))})),n&&a.addEventListener("blocked",(()=>n())),o.then((t=>{r&&t.addEventListener("close",(()=>r())),i&&t.addEventListener("versionchange",(()=>i()))})).catch((()=>{})),o}("workbox-expiration",1,{upgrade:this.N.bind(this)})),this.t}}class v{constructor(t,e={}){this.P=!1,this.W=!1,this.S=e.maxEntries,this.K=e.maxAgeSeconds,this.L=e.matchOptions,this.M=t,this.H=new k(t)}async expireEntries(){if(this.P)return void(this.W=!0);this.P=!0;const t=this.K?Date.now()-1e3*this.K:0,n=await this.H.expireEntries(t,this.S),s=await self.caches.open(this.M);for(const t of n)await s.delete(t,this.L);this.P=!1,this.W&&(this.W=!1,e.dontWaitFor(this.expireEntries()))}async updateTimestamp(t){await this.H.setTimestamp(t,Date.now())}async isURLExpired(t){if(this.K){const e=await this.H.getTimestamp(t),n=Date.now()-1e3*this.K;return void 0===e||e<n}return!1}async delete(){this.W=!1,await this.H.expireEntries(1/0)}}return t.CacheExpiration=v,t.ExpirationPlugin=class{constructor(t={}){this.cachedResponseWillBeUsed=async({event:t,request:n,cacheName:s,cachedResponse:i})=>{if(!i)return null;const r=this.$(i),a=this.J(s);e.dontWaitFor(a.expireEntries());const o=a.updateTimestamp(n.url);if(t)try{t.waitUntil(o)}catch(t){}return r?i:null},this.cacheDidUpdate=async({cacheName:t,request:e})=>{const n=this.J(t);await n.updateTimestamp(e.url),await n.expireEntries()},this.V=t,this.K=t.maxAgeSeconds,this.X=new Map,t.purgeOnQuotaError&&s.registerQuotaErrorCallback((()=>this.deleteCacheAndMetadata()))}J(t){if(t===n.cacheNames.getRuntimeName())throw new i.WorkboxError("expire-custom-caches-only");let e=this.X.get(t);return e||(e=new v(t,this.V),this.X.set(t,e)),e}$(t){if(!this.K)return!0;const e=this.Y(t);if(null===e)return!0;return e>=Date.now()-1e3*this.K}Y(t){if(!t.headers.has("date"))return null;const e=t.headers.get("date"),n=new Date(e).getTime();return isNaN(n)?null:n}async deleteCacheAndMetadata(){for(const[t,e]of this.X)await self.caches.delete(t),await e.delete();this.X=new Map}},t}({},workbox.core._private,workbox.core._private,workbox.core,workbox.core._private); | ||
this.workbox=this.workbox||{},this.workbox.expiration=function(t,e,n,s,i){"use strict";function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t}).apply(this,arguments)}let a,o;const c=new WeakMap,u=new WeakMap,h=new WeakMap,f=new WeakMap,l=new WeakMap;let d={get(t,e,n){if(t instanceof IDBTransaction){if("done"===e)return u.get(t);if("objectStoreNames"===e)return t.objectStoreNames||h.get(t);if("store"===e)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return D(t[e])},set:(t,e,n)=>(t[e]=n,!0),has:(t,e)=>t instanceof IDBTransaction&&("done"===e||"store"===e)||e in t};function w(t){return t!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(o||(o=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(t)?function(...e){return t.apply(m(this),e),D(c.get(this))}:function(...e){return D(t.apply(m(this),e))}:function(e,...n){const s=t.call(m(this),e,...n);return h.set(s,e.sort?e.sort():[e]),D(s)}}function p(t){return"function"==typeof t?w(t):(t instanceof IDBTransaction&&function(t){if(u.has(t))return;const e=new Promise(((e,n)=>{const s=()=>{t.removeEventListener("complete",i),t.removeEventListener("error",r),t.removeEventListener("abort",r)},i=()=>{e(),s()},r=()=>{n(t.error||new DOMException("AbortError","AbortError")),s()};t.addEventListener("complete",i),t.addEventListener("error",r),t.addEventListener("abort",r)}));u.set(t,e)}(t),e=t,(a||(a=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])).some((t=>e instanceof t))?new Proxy(t,d):t);var e}function D(t){if(t instanceof IDBRequest)return function(t){const e=new Promise(((e,n)=>{const s=()=>{t.removeEventListener("success",i),t.removeEventListener("error",r)},i=()=>{e(D(t.result)),s()},r=()=>{n(t.error),s()};t.addEventListener("success",i),t.addEventListener("error",r)}));return e.then((e=>{e instanceof IDBCursor&&c.set(e,t)})).catch((()=>{})),l.set(e,t),e}(t);if(f.has(t))return f.get(t);const e=p(t);return e!==t&&(f.set(t,e),l.set(e,t)),e}const m=t=>l.get(t);const b=["get","getKey","getAll","getAllKeys","count"],y=["put","add","delete","clear"],I=new Map;function B(t,e){if(!(t instanceof IDBDatabase)||e in t||"string"!=typeof e)return;if(I.get(e))return I.get(e);const n=e.replace(/FromIndex$/,""),s=e!==n,i=y.includes(n);if(!(n in(s?IDBIndex:IDBObjectStore).prototype)||!i&&!b.includes(n))return;const r=async function(t,...e){const r=this.transaction(t,i?"readwrite":"readonly");let a=r.store;return s&&(a=a.index(e.shift())),(await Promise.all([a[n](...e),i&&r.done]))[0]};return I.set(e,r),r}d=(t=>r({},t,{get:(e,n,s)=>B(e,n)||t.get(e,n,s),has:(e,n)=>!!B(e,n)||t.has(e,n)}))(d);try{self["workbox:expiration:6.3.0"]&&_()}catch(t){}const g="cache-entries",x=t=>{const e=new URL(t,location.href);return e.hash="",e.href};class k{constructor(t){this.t=null,this.M=t}i(t){const e=t.createObjectStore(g,{keyPath:"id"});e.createIndex("cacheName","cacheName",{unique:!1}),e.createIndex("timestamp","timestamp",{unique:!1})}N(t){this.i(t),this.M&&function(t,{blocked:e}={}){const n=indexedDB.deleteDatabase(t);e&&n.addEventListener("blocked",(()=>e())),D(n).then((()=>{}))}(this.M)}async setTimestamp(t,e){const n={url:t=x(t),timestamp:e,cacheName:this.M,id:this.T(t)},s=(await this.getDb()).transaction(g,"readwrite",{durability:"relaxed"});await s.store.put(n),await s.done}async getTimestamp(t){const e=await this.getDb(),n=await e.get(g,this.T(t));return null==n?void 0:n.timestamp}async expireEntries(t,e){const n=await this.getDb();let s=await n.transaction(g).store.index("timestamp").openCursor(null,"prev");const i=[];let r=0;for(;s;){const n=s.value;n.cacheName===this.M&&(t&&n.timestamp<t||e&&r>=e?i.push(s.value):r++),s=await s.continue()}const a=[];for(const t of i)await n.delete(g,t.id),a.push(t.url);return a}T(t){return this.M+"|"+x(t)}async getDb(){return this.t||(this.t=await function(t,e,{blocked:n,upgrade:s,blocking:i,terminated:r}={}){const a=indexedDB.open(t,e),o=D(a);return s&&a.addEventListener("upgradeneeded",(t=>{s(D(a.result),t.oldVersion,t.newVersion,D(a.transaction))})),n&&a.addEventListener("blocked",(()=>n())),o.then((t=>{r&&t.addEventListener("close",(()=>r())),i&&t.addEventListener("versionchange",(()=>i()))})).catch((()=>{})),o}("workbox-expiration",1,{upgrade:this.N.bind(this)})),this.t}}class v{constructor(t,e={}){this.P=!1,this.W=!1,this.S=e.maxEntries,this.K=e.maxAgeSeconds,this.L=e.matchOptions,this.M=t,this.H=new k(t)}async expireEntries(){if(this.P)return void(this.W=!0);this.P=!0;const t=this.K?Date.now()-1e3*this.K:0,n=await this.H.expireEntries(t,this.S),s=await self.caches.open(this.M);for(const t of n)await s.delete(t,this.L);this.P=!1,this.W&&(this.W=!1,e.dontWaitFor(this.expireEntries()))}async updateTimestamp(t){await this.H.setTimestamp(t,Date.now())}async isURLExpired(t){if(this.K){const e=await this.H.getTimestamp(t),n=Date.now()-1e3*this.K;return void 0===e||e<n}return!1}async delete(){this.W=!1,await this.H.expireEntries(1/0)}}return t.CacheExpiration=v,t.ExpirationPlugin=class{constructor(t={}){this.cachedResponseWillBeUsed=async({event:t,request:n,cacheName:s,cachedResponse:i})=>{if(!i)return null;const r=this.$(i),a=this.J(s);e.dontWaitFor(a.expireEntries());const o=a.updateTimestamp(n.url);if(t)try{t.waitUntil(o)}catch(t){}return r?i:null},this.cacheDidUpdate=async({cacheName:t,request:e})=>{const n=this.J(t);await n.updateTimestamp(e.url),await n.expireEntries()},this.V=t,this.K=t.maxAgeSeconds,this.X=new Map,t.purgeOnQuotaError&&s.registerQuotaErrorCallback((()=>this.deleteCacheAndMetadata()))}J(t){if(t===n.cacheNames.getRuntimeName())throw new i.WorkboxError("expire-custom-caches-only");let e=this.X.get(t);return e||(e=new v(t,this.V),this.X.set(t,e)),e}$(t){if(!this.K)return!0;const e=this.Y(t);if(null===e)return!0;return e>=Date.now()-1e3*this.K}Y(t){if(!t.headers.has("date"))return null;const e=t.headers.get("date"),n=new Date(e).getTime();return isNaN(n)?null:n}async deleteCacheAndMetadata(){for(const[t,e]of this.X)await self.caches.delete(t),await e.delete();this.X=new Map}},t}({},workbox.core._private,workbox.core._private,workbox.core,workbox.core._private); | ||
//# sourceMappingURL=workbox-expiration.prod.js.map |
@@ -84,4 +84,5 @@ /* | ||
this._isRunning = true; | ||
const minTimestamp = this._maxAgeSeconds ? | ||
Date.now() - (this._maxAgeSeconds * 1000) : 0; | ||
const minTimestamp = this._maxAgeSeconds | ||
? Date.now() - this._maxAgeSeconds * 1000 | ||
: 0; | ||
const urlsExpired = await this._timestampModel.expireEntries(minTimestamp, this._maxEntries); | ||
@@ -99,4 +100,3 @@ // Delete URLs from the cache | ||
`'${this._cacheName}' cache.`); | ||
logger.log(`Expired the following ${urlsExpired.length === 1 ? | ||
'URL' : 'URLs'}:`); | ||
logger.log(`Expired the following ${urlsExpired.length === 1 ? 'URL' : 'URLs'}:`); | ||
urlsExpired.forEach((url) => logger.log(` ${url}`)); | ||
@@ -156,4 +156,4 @@ logger.groupEnd(); | ||
const timestamp = await this._timestampModel.getTimestamp(url); | ||
const expireOlderThan = Date.now() - (this._maxAgeSeconds * 1000); | ||
return timestamp !== undefined ? (timestamp < expireOlderThan) : true; | ||
const expireOlderThan = Date.now() - this._maxAgeSeconds * 1000; | ||
return timestamp !== undefined ? timestamp < expireOlderThan : true; | ||
} | ||
@@ -160,0 +160,0 @@ } |
@@ -70,3 +70,3 @@ /* | ||
*/ | ||
this.cachedResponseWillBeUsed = async ({ event, request, cacheName, cachedResponse }) => { | ||
this.cachedResponseWillBeUsed = async ({ event, request, cacheName, cachedResponse, }) => { | ||
if (!cachedResponse) { | ||
@@ -110,3 +110,3 @@ return null; | ||
*/ | ||
this.cacheDidUpdate = async ({ cacheName, request }) => { | ||
this.cacheDidUpdate = async ({ cacheName, request, }) => { | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -204,3 +204,3 @@ assert.isType(cacheName, 'string', { | ||
const now = Date.now(); | ||
return dateHeaderTimestamp >= now - (this._maxAgeSeconds * 1000); | ||
return dateHeaderTimestamp >= now - this._maxAgeSeconds * 1000; | ||
} | ||
@@ -207,0 +207,0 @@ /** |
@@ -7,2 +7,2 @@ import { CacheExpiration } from './CacheExpiration.js'; | ||
*/ | ||
export { CacheExpiration, ExpirationPlugin, }; | ||
export { CacheExpiration, ExpirationPlugin }; |
@@ -14,2 +14,2 @@ /* | ||
*/ | ||
export { CacheExpiration, ExpirationPlugin, }; | ||
export { CacheExpiration, ExpirationPlugin }; |
@@ -71,8 +71,8 @@ import '../_version.js'; | ||
/** | ||
* Returns an open connection to the database. | ||
* | ||
* @private | ||
*/ | ||
* Returns an open connection to the database. | ||
* | ||
* @private | ||
*/ | ||
private getDb; | ||
} | ||
export { CacheTimestampsModel }; |
@@ -83,3 +83,5 @@ /* | ||
const db = await this.getDb(); | ||
const tx = db.transaction(CACHE_OBJECT_STORE, 'readwrite', { durability: 'relaxed' }); | ||
const tx = db.transaction(CACHE_OBJECT_STORE, 'readwrite', { | ||
durability: 'relaxed', | ||
}); | ||
await tx.store.put(entry); | ||
@@ -114,3 +116,6 @@ await tx.done; | ||
const db = await this.getDb(); | ||
let cursor = await db.transaction(CACHE_OBJECT_STORE).store.index('timestamp').openCursor(null, 'prev'); | ||
let cursor = await db | ||
.transaction(CACHE_OBJECT_STORE) | ||
.store.index('timestamp') | ||
.openCursor(null, 'prev'); | ||
const entriesToDelete = []; | ||
@@ -169,6 +174,6 @@ let entriesNotDeletedCount = 0; | ||
/** | ||
* Returns an open connection to the database. | ||
* | ||
* @private | ||
*/ | ||
* Returns an open connection to the database. | ||
* | ||
* @private | ||
*/ | ||
async getDb() { | ||
@@ -175,0 +180,0 @@ if (!this._db) { |
{ | ||
"name": "workbox-expiration", | ||
"version": "6.3.0", | ||
"version": "6.4.0", | ||
"license": "MIT", | ||
@@ -25,6 +25,6 @@ "author": "Google's Web DevRel Team", | ||
"dependencies": { | ||
"idb": "^6.0.0", | ||
"workbox-core": "6.3.0" | ||
"idb": "^6.1.4", | ||
"workbox-core": "6.4.0" | ||
}, | ||
"gitHead": "03055e64014a46f6cc977a3a50ad814c6409d36a" | ||
"gitHead": "cdad230c678a3626c217615d5792eb0f1c77194c" | ||
} |
// @ts-ignore | ||
try{self['workbox:expiration:6.3.0']&&_()}catch(e){} | ||
try{self['workbox:expiration:6.4.0']&&_()}catch(e){} |
@@ -18,3 +18,2 @@ /* | ||
interface CacheExpirationConfig { | ||
@@ -108,7 +107,10 @@ maxEntries?: number; | ||
const minTimestamp = this._maxAgeSeconds ? | ||
Date.now() - (this._maxAgeSeconds * 1000) : 0; | ||
const minTimestamp = this._maxAgeSeconds | ||
? Date.now() - this._maxAgeSeconds * 1000 | ||
: 0; | ||
const urlsExpired = await this._timestampModel.expireEntries( | ||
minTimestamp, this._maxEntries); | ||
minTimestamp, | ||
this._maxEntries, | ||
); | ||
@@ -124,8 +126,10 @@ // Delete URLs from the cache | ||
logger.groupCollapsed( | ||
`Expired ${urlsExpired.length} ` + | ||
`${urlsExpired.length === 1 ? 'entry' : 'entries'} and removed ` + | ||
`${urlsExpired.length === 1 ? 'it' : 'them'} from the ` + | ||
`'${this._cacheName}' cache.`); | ||
logger.log(`Expired the following ${urlsExpired.length === 1 ? | ||
'URL' : 'URLs'}:`); | ||
`Expired ${urlsExpired.length} ` + | ||
`${urlsExpired.length === 1 ? 'entry' : 'entries'} and removed ` + | ||
`${urlsExpired.length === 1 ? 'it' : 'them'} from the ` + | ||
`'${this._cacheName}' cache.`, | ||
); | ||
logger.log( | ||
`Expired the following ${urlsExpired.length === 1 ? 'URL' : 'URLs'}:`, | ||
); | ||
urlsExpired.forEach((url) => logger.log(` ${url}`)); | ||
@@ -187,4 +191,4 @@ logger.groupEnd(); | ||
const timestamp = await this._timestampModel.getTimestamp(url); | ||
const expireOlderThan = Date.now() - (this._maxAgeSeconds * 1000); | ||
return timestamp !== undefined ? (timestamp < expireOlderThan) : true; | ||
const expireOlderThan = Date.now() - this._maxAgeSeconds * 1000; | ||
return timestamp !== undefined ? timestamp < expireOlderThan : true; | ||
} | ||
@@ -191,0 +195,0 @@ } |
@@ -149,3 +149,3 @@ /* | ||
cacheName, | ||
cachedResponse | ||
cachedResponse, | ||
}) => { | ||
@@ -173,5 +173,7 @@ if (!cachedResponse) { | ||
if ('request' in event) { | ||
logger.warn(`Unable to ensure service worker stays alive when ` + | ||
`updating cache entry for ` + | ||
`'${getFriendlyURL((event as FetchEvent).request.url)}'.`); | ||
logger.warn( | ||
`Unable to ensure service worker stays alive when ` + | ||
`updating cache entry for ` + | ||
`'${getFriendlyURL((event as FetchEvent).request.url)}'.`, | ||
); | ||
} | ||
@@ -183,3 +185,3 @@ } | ||
return isFresh ? cachedResponse : null; | ||
} | ||
}; | ||
@@ -210,3 +212,3 @@ /** | ||
const now = Date.now(); | ||
return dateHeaderTimestamp >= now - (this._maxAgeSeconds * 1000); | ||
return dateHeaderTimestamp >= now - this._maxAgeSeconds * 1000; | ||
} | ||
@@ -253,3 +255,3 @@ | ||
cacheName, | ||
request | ||
request, | ||
}) => { | ||
@@ -274,5 +276,4 @@ if (process.env.NODE_ENV !== 'production') { | ||
await cacheExpiration.expireEntries(); | ||
} | ||
}; | ||
/** | ||
@@ -279,0 +280,0 @@ * This is a helper method that performs two operations: |
@@ -13,3 +13,2 @@ /* | ||
/** | ||
@@ -19,5 +18,2 @@ * @module workbox-expiration | ||
export { | ||
CacheExpiration, | ||
ExpirationPlugin, | ||
}; | ||
export {CacheExpiration, ExpirationPlugin}; |
@@ -12,3 +12,2 @@ /* | ||
const DB_NAME = 'workbox-expiration'; | ||
@@ -24,3 +23,2 @@ const CACHE_OBJECT_STORE = 'cache-entries'; | ||
interface CacheTimestampsModelEntry { | ||
@@ -58,3 +56,2 @@ id: string; | ||
this._cacheName = cacheName; | ||
} | ||
@@ -81,3 +78,2 @@ | ||
objStore.createIndex('timestamp', 'timestamp', {unique: false}); | ||
} | ||
@@ -118,3 +114,5 @@ | ||
const db = await this.getDb(); | ||
const tx = db.transaction(CACHE_OBJECT_STORE, 'readwrite', {durability: 'relaxed'}); | ||
const tx = db.transaction(CACHE_OBJECT_STORE, 'readwrite', { | ||
durability: 'relaxed', | ||
}); | ||
await tx.store.put(entry); | ||
@@ -149,5 +147,11 @@ await tx.done; | ||
*/ | ||
async expireEntries(minTimestamp: number, maxCount?: number): Promise<string[]> { | ||
async expireEntries( | ||
minTimestamp: number, | ||
maxCount?: number, | ||
): Promise<string[]> { | ||
const db = await this.getDb(); | ||
let cursor = await db.transaction(CACHE_OBJECT_STORE).store.index('timestamp').openCursor(null, 'prev') | ||
let cursor = await db | ||
.transaction(CACHE_OBJECT_STORE) | ||
.store.index('timestamp') | ||
.openCursor(null, 'prev'); | ||
const entriesToDelete: CacheTimestampsModelEntry[] = []; | ||
@@ -162,4 +166,6 @@ let entriesNotDeletedCount = 0; | ||
// if we already have the max number allowed. | ||
if ((minTimestamp && result.timestamp < minTimestamp) || | ||
(maxCount && entriesNotDeletedCount >= maxCount)) { | ||
if ( | ||
(minTimestamp && result.timestamp < minTimestamp) || | ||
(maxCount && entriesNotDeletedCount >= maxCount) | ||
) { | ||
// TODO(philipwalton): we should be able to delete the | ||
@@ -182,3 +188,2 @@ // entry right here, but doing so causes an iteration | ||
// TODO(philipwalton): once the Safari bug in the following issue is fixed, | ||
@@ -213,6 +218,6 @@ // we should be able to remove this loop and do the entry deletion in the | ||
/** | ||
* Returns an open connection to the database. | ||
* | ||
* @private | ||
*/ | ||
* Returns an open connection to the database. | ||
* | ||
* @private | ||
*/ | ||
private async getDb() { | ||
@@ -219,0 +224,0 @@ if (!this._db) { |
@@ -8,8 +8,4 @@ { | ||
}, | ||
"include": [ | ||
"src/**/*.ts" | ||
], | ||
"references": [ | ||
{ "path": "../workbox-core/" } | ||
] | ||
"include": ["src/**/*.ts"], | ||
"references": [{"path": "../workbox-core/"}] | ||
} |
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
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
2416
226985
+ Addedworkbox-core@6.4.0(transitive)
- Removedworkbox-core@6.3.0(transitive)
Updatedidb@^6.1.4
Updatedworkbox-core@6.4.0