mirror of
https://github.com/skidoodle/hostinfo
synced 2026-04-28 09:37:37 +02:00
clean geocache
This commit is contained in:
@@ -53,5 +53,23 @@ export const StorageService = {
|
|||||||
const key = `geo_${ip.replace(/:/g, '_')}`;
|
const key = `geo_${ip.replace(/:/g, '_')}`;
|
||||||
const entry: CacheEntry = { data, timestamp: Date.now() };
|
const entry: CacheEntry = { data, timestamp: Date.now() };
|
||||||
await browser.storage.local.set({ [key]: entry });
|
await browser.storage.local.set({ [key]: entry });
|
||||||
|
},
|
||||||
|
|
||||||
|
async cleanExpiredGeoCache(): Promise<void> {
|
||||||
|
const res = await browser.storage.local.get(null);
|
||||||
|
const keysToRemove: string[] = [];
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(res)) {
|
||||||
|
if (key.startsWith('geo_')) {
|
||||||
|
const entry = value as CacheEntry;
|
||||||
|
if (Date.now() - entry.timestamp > CACHE_TTL) {
|
||||||
|
keysToRemove.push(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keysToRemove.length > 0) {
|
||||||
|
await browser.storage.local.remove(keysToRemove);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-1
@@ -12,7 +12,8 @@ export default defineConfig({
|
|||||||
'tabs',
|
'tabs',
|
||||||
'webRequest',
|
'webRequest',
|
||||||
'webNavigation',
|
'webNavigation',
|
||||||
'storage'
|
'storage',
|
||||||
|
'alarms'
|
||||||
],
|
],
|
||||||
host_permissions: [
|
host_permissions: [
|
||||||
'<all_urls>',
|
'<all_urls>',
|
||||||
|
|||||||
Reference in New Issue
Block a user