common-ui/src/lib/caching/cache-utils.ts
2022-07-26 17:42:36 +03:00

26 lines
777 B
TypeScript

import { InjectionToken } from '@angular/core';
import { DynamicCaches } from './dynamic-cache';
export const APP_LEVEL_CACHE = 'app-level-cache';
export const DYNAMIC_CACHES = new InjectionToken<DynamicCaches>('dynamic-caches');
export async function wipeAllCaches() {
console.log('get caches keys');
const keys = await caches.keys();
for (const cache of keys) {
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 });
}