From 30045f947af8012f25403c7a934d65dbd390a2ec Mon Sep 17 00:00:00 2001 From: Timo Bejan Date: Wed, 25 May 2022 17:44:29 +0300 Subject: [PATCH] RED-3800 cache cleanup --- apps/red-ui/src/app/services/config.service.ts | 4 ++-- libs/red-cache/src/lib/caches/cache-utils.ts | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/red-ui/src/app/services/config.service.ts b/apps/red-ui/src/app/services/config.service.ts index ce80e5511..ff1381bbd 100644 --- a/apps/red-ui/src/app/services/config.service.ts +++ b/apps/red-ui/src/app/services/config.service.ts @@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http'; import { Title } from '@angular/platform-browser'; import packageInfo from '../../../../../package.json'; import envConfig from '../../assets/config/config.json'; -import { CacheApiService, wipeCaches } from '@red/cache'; +import { CacheApiService, wipeAllCaches, wipeCaches } from '@red/cache'; import { Observable } from 'rxjs'; import { tap } from 'rxjs/operators'; import { AppConfig } from '@red/domain'; @@ -47,7 +47,7 @@ export class ConfigService { console.log('[REDACTION] Last app version: ', lastVersion, ' current version ', version); if (lastVersion !== version) { console.warn('[REDACTION] Version-mismatch - wiping caches!'); - await wipeCaches(); + await wipeAllCaches(); } await this._cacheApiService.cacheValue('FRONTEND_APP_VERSION', version); }); diff --git a/libs/red-cache/src/lib/caches/cache-utils.ts b/libs/red-cache/src/lib/caches/cache-utils.ts index 95d6e4945..76074c0fd 100644 --- a/libs/red-cache/src/lib/caches/cache-utils.ts +++ b/libs/red-cache/src/lib/caches/cache-utils.ts @@ -19,6 +19,13 @@ export const DYNAMIC_CACHES = [ }, ]; +export async function wipeAllCaches() { + const keys = await caches.keys(); + for (const cache of keys) { + await caches.delete(cache); + } +} + export async function wipeCaches(logoutDependant: boolean = false) { await caches.delete(APP_LEVEL_CACHE); for (const cache of DYNAMIC_CACHES) {