27 lines
703 B
TypeScript
27 lines
703 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() {
|
|
const keys = (await caches?.keys()) ?? [];
|
|
for (const cache of keys) {
|
|
await wipeCache(cache);
|
|
}
|
|
}
|
|
|
|
export function wipeCache(cacheName: string) {
|
|
return caches?.delete(cacheName);
|
|
}
|
|
|
|
export async function wipeCacheEntry(cacheName: string, entry: string) {
|
|
if (!caches) {
|
|
return;
|
|
}
|
|
|
|
const cache = await caches.open(cacheName);
|
|
return cache.delete(entry, { ignoreSearch: false });
|
|
}
|