red-ui/libs/red-cache/src/lib/caches/cache-utils.ts
2021-06-07 14:37:08 +03:00

40 lines
1001 B
TypeScript

export const APP_LEVEL_CACHE = 'app-level-cache';
export const DYNAMIC_CACHES = [
{
urls: ['/assets/icons', '/assets/wv-resources'],
name: 'cached-assets',
clearOnLogout: false,
maxAge: 24 * 3600,
maxSize: 1000,
methods: ['GET']
},
{
urls: ['/download/original'],
name: 'files',
maxAge: 3600 * 24 * 7,
maxSize: 1000,
clearOnLogout: true,
methods: ['GET']
}
];
export async function wipeCaches(logoutDependant: boolean = false) {
await caches.delete(APP_LEVEL_CACHE);
for (const cache of DYNAMIC_CACHES) {
if (!logoutDependant) {
caches.delete(cache.name);
}
if (logoutDependant && cache.clearOnLogout) {
caches.delete(cache.name);
}
}
}
export async function wipeCacheEntry(cacheName: string, entry: string) {
caches.open(cacheName).then(cache => {
cache.delete(entry, { ignoreSearch: false });
});
}