diff --git a/playlet-web/src/lib/Api/InvidiousApi.ts b/playlet-web/src/lib/Api/InvidiousApi.ts index 797624d8..d3bddbe7 100644 --- a/playlet-web/src/lib/Api/InvidiousApi.ts +++ b/playlet-web/src/lib/Api/InvidiousApi.ts @@ -284,12 +284,14 @@ export class InvidiousApi { try { const cacheData = JSON.parse(cache); if (cacheData.timestamp + cacheSeconds * 1000 < Date.now()) { + this.deleteCache(url); return null; } console.log(`Cache hit for ${url}`); return cacheData.data; } catch (error) { console.error(error); + this.deleteCache(url); return null; } } @@ -305,6 +307,11 @@ export class InvidiousApi { localStorage.setItem(cacheKey, JSON.stringify(cacheData)); } + private deleteCache(url: string) { + const cacheKey = this.getCacheKey(url); + localStorage.removeItem(cacheKey); + } + private getCacheKey(url: string) { return `v1:${url}`; }