common-ui/src/lib/caching/cache-utils.ts
2023-03-31 12:30:39 +03:00

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 });
}