check caches for undefined
This commit is contained in:
parent
2761140489
commit
7ca5db9cee
@ -12,7 +12,7 @@ export class CacheApiService {
|
||||
}
|
||||
|
||||
get cachesAvailable(): boolean {
|
||||
return !!window.caches;
|
||||
return !!caches;
|
||||
}
|
||||
|
||||
cacheRequest(request: HttpRequest<any>, httpResponse: HttpResponse<any>) {
|
||||
@ -20,6 +20,10 @@ export class CacheApiService {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.cachesAvailable) {
|
||||
return;
|
||||
}
|
||||
|
||||
const url = this._buildUrl(request);
|
||||
for (const dynCache of this._dynamicCaches) {
|
||||
for (const cacheUrl of dynCache.urls) {
|
||||
@ -35,6 +39,10 @@ export class CacheApiService {
|
||||
|
||||
async wipeCaches(logoutDependant = false) {
|
||||
// console.log('[CACHE-API] delete app level cache ');
|
||||
if (!this.cachesAvailable) {
|
||||
return;
|
||||
}
|
||||
|
||||
await caches.delete(APP_LEVEL_CACHE);
|
||||
|
||||
for (const cache of this._dynamicCaches) {
|
||||
@ -234,6 +242,10 @@ export class CacheApiService {
|
||||
|
||||
private async _handleCacheExpiration(dynCache: DynamicCache, now: number) {
|
||||
// console.log('[CACHE-API] checking cache expiration');
|
||||
if (!this.cachesAvailable) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cache = await caches.open(dynCache.name);
|
||||
let keys = await cache.keys();
|
||||
// removed expired;
|
||||
|
||||
@ -7,7 +7,7 @@ export const DYNAMIC_CACHES = new InjectionToken<DynamicCaches>('dynamic-caches'
|
||||
|
||||
export async function wipeAllCaches() {
|
||||
console.log('get caches keys');
|
||||
const keys = await caches.keys();
|
||||
const keys = (await caches?.keys()) ?? [];
|
||||
for (const cache of keys) {
|
||||
await wipeCache(cache);
|
||||
}
|
||||
@ -15,10 +15,14 @@ export async function wipeAllCaches() {
|
||||
|
||||
export function wipeCache(cacheName: string) {
|
||||
console.log('delete cache: ', cacheName);
|
||||
return caches.delete(cacheName);
|
||||
return caches?.delete(cacheName);
|
||||
}
|
||||
|
||||
export async function wipeCacheEntry(cacheName: string, entry: string) {
|
||||
if (!caches) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('open cache: ', cacheName);
|
||||
const cache = await caches.open(cacheName);
|
||||
return cache.delete(entry, { ignoreSearch: false });
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user