diff --git a/main/preload.ts b/main/preload.ts index bad47d1a5..78a2f3c0a 100644 --- a/main/preload.ts +++ b/main/preload.ts @@ -12,7 +12,7 @@ import { logError } from './utils/logging'; import { ElectronFile } from './types'; import { getEncryptionKey, setEncryptionKey } from './utils/safeStorage'; import { clearElectronStore } from './utils/electronStore'; -import { openLocalCache } from './utils/cache'; +import { openDiskCache, clearDiskCache } from './utils/cache'; // Patch the global WebSocket constructor to use the correct DevServer url const fixHotReloadNext12 = () => { @@ -194,5 +194,6 @@ windowObject['ElectronAPIs'] = { getEncryptionKey, setEncryptionKey, clearElectronStore, - openLocalCache, + openDiskCache, + clearDiskCache, }; diff --git a/main/utils/cache.ts b/main/utils/cache.ts index 22617a30f..2edd769f4 100644 --- a/main/utils/cache.ts +++ b/main/utils/cache.ts @@ -1,6 +1,6 @@ import { ipcRenderer } from 'electron/renderer'; import path from 'path'; -import { readFile, writeFile, existsSync, mkdir } from 'promise-fs'; +import { readFile, writeFile, existsSync, mkdir, rmSync } from 'promise-fs'; import crypto from 'crypto'; import DiskLRUService from './diskLRU'; @@ -12,7 +12,7 @@ const getCacheDir = async () => { return path.join(systemCacheDir, CACHE_DIR); }; -export async function openLocalCache(cacheName: string) { +export async function openDiskCache(cacheName: string) { const cacheDir = await getCacheDir(); const cacheBucketDir = path.join(cacheDir, cacheName); if (!existsSync(cacheBucketDir)) { @@ -21,6 +21,11 @@ export async function openLocalCache(cacheName: string) { return new DiskCache(cacheBucketDir); } +export async function clearDiskCache() { + const cacheDir = await getCacheDir(); + rmSync(cacheDir, { recursive: true, force: true }); +} + class DiskCache { constructor(private cacheBucketDir: string) {}