add clearDiskCache API
This commit is contained in:
parent
8e03f5d899
commit
c797dca835
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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) {}
|
||||
|
||||
|
|
Loading…
Reference in a new issue