清除 Electron 中的缓存数据

Electron 将其缓存存储在以下文件夹中:

window :
C:\Users<user>\AppData\Roaming<yourAppName>\Cache

Linux:
/home//.config//Cache

操作系统:
/Users//Library/Application Support//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);
  }
}
posted @   龙陌  阅读(1045)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
点击右上角即可分享
微信分享提示