clear expired and invalid cache
This commit is contained in:
1 parent
0377f075be
commit
e8b6cd1588
1 file changed
+7
@@ -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}`;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user