diff --git a/src/lib/caching/cache-api.service.ts b/src/lib/caching/cache-api.service.ts index 856cfed..3e858eb 100644 --- a/src/lib/caching/cache-api.service.ts +++ b/src/lib/caching/cache-api.service.ts @@ -2,7 +2,7 @@ import { Inject, Injectable } from '@angular/core'; import { HttpEvent, HttpHeaders, HttpRequest, HttpResponse } from '@angular/common/http'; import { from, Observable, of, throwError } from 'rxjs'; import { map, mergeMap } from 'rxjs/operators'; -import { APP_LEVEL_CACHE, DYNAMIC_CACHES } from './cache-utils'; +import { APP_LEVEL_CACHE, DYNAMIC_CACHES, wipeCache } from './cache-utils'; import { DynamicCache, DynamicCaches } from './dynamic-cache'; @Injectable() @@ -24,6 +24,7 @@ export class CacheApiService { for (const dynCache of this._dynamicCaches) { for (const cacheUrl of dynCache.urls) { if (url.indexOf(cacheUrl) >= 0) { + console.log('[CACHE-API] open cache: ', dynCache.name); return caches.open(dynCache.name).then(cache => this._handleFetchResponse(httpResponse, dynCache, cache, url)); } } @@ -33,15 +34,16 @@ export class CacheApiService { } async wipeCaches(logoutDependant = false) { + console.log('[CACHE-API] delete app level cache '); await caches.delete(APP_LEVEL_CACHE); for (const cache of this._dynamicCaches) { if (!logoutDependant) { - await caches.delete(cache.name); + await wipeCache(cache.name); } if (logoutDependant && cache.clearOnLogout) { - await caches.delete(cache.name); + await wipeCache(cache.name); } } } @@ -49,6 +51,7 @@ export class CacheApiService { getCachedRequest(request: HttpRequest): Observable> { const url = this._buildUrl(request); + console.log('[CACHE-API] get cached request: ', url); return from(caches.match(url)).pipe( mergeMap(response => { if (response) { @@ -75,6 +78,7 @@ export class CacheApiService { return Promise.resolve(); } + console.log('[CACHE-API] cache value: ', name); const cache = await caches.open(APP_LEVEL_CACHE); const string = JSON.stringify(valueReference); const expires = new Date().getTime() + ttl * 1000; @@ -93,6 +97,7 @@ export class CacheApiService { return Promise.resolve(undefined); } + console.log('[CACHE-API] get cached value: ', name); const cache = await caches.open(APP_LEVEL_CACHE); const result = await cache.match(name); if (!result) { @@ -228,6 +233,7 @@ export class CacheApiService { } private async _handleCacheExpiration(dynCache: DynamicCache, now: number) { + console.log('[CACHE-API] checking cache expiration'); const cache = await caches.open(dynCache.name); let keys = await cache.keys(); // removed expired; diff --git a/src/lib/caching/cache-utils.ts b/src/lib/caching/cache-utils.ts index 4e406d6..3afa506 100644 --- a/src/lib/caching/cache-utils.ts +++ b/src/lib/caching/cache-utils.ts @@ -6,17 +6,20 @@ export const APP_LEVEL_CACHE = 'app-level-cache'; export const DYNAMIC_CACHES = new InjectionToken('dynamic-caches'); export async function wipeAllCaches() { + console.log('get caches keys'); const keys = await caches.keys(); for (const cache of keys) { - await caches.delete(cache); + await wipeCache(cache); } } export function wipeCache(cacheName: string) { + console.log('delete cache: ', cacheName); return caches.delete(cacheName); } export async function wipeCacheEntry(cacheName: string, entry: string) { + console.log('open cache: ', cacheName); const cache = await caches.open(cacheName); return cache.delete(entry, { ignoreSearch: false }); }