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);
}
}
标签:directoryPath,fs,清除,Cache,curPath,deletePath,Electron,缓存数据,file
From: https://www.cnblogs.com/longmo666/p/18367329