|
electron 清理页面缓存,找到electron 缓存目录 删除 Code Cache
- 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);
- }
- }
复制代码
|
|