Electron 將其快取儲存在以下資料夾中:
window :
C:\Users<user>\AppData\Roaming<yourAppName>\Cache
Linux:
/home/
作業系統:
/Users/
let cache = app.getPath('cache');
// 獲取快取的路徑
const cachePath = path.join(cache, 'appName');
// 清理快取目錄下的檔案
if (fs.existsSync(cachePath)) {
var deletePath = ['blob_storage', 'Code Cache'];
for (var i = 0; i < deletePath.length; i++) {
deleteDirectoryRecursive(path.join(cachePath, deletePath[i]));
}
}
function deleteDirectoryRecursive(directoryPath) {
if (fs.existsSync(directoryPath)) {
fs.readdirSync(directoryPath).forEach(function(file, index) {
var curPath = path.join(directoryPath, file);
if (fs.lstatSync(curPath).isDirectory()) { // recurse
deleteDirectoryRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(directoryPath);
}
}