node.js 如何清除 Electron(atom shell) 中的缓存数据?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31446782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to clear the cache data in Electron(atom shell)?
提问by neel
I want to clear cache data in Electron(atom-shell). I don't find any api like gui.App.clearCache()(node-webkit api to clear cache data) in Electron. If you find any api or any other way please let me know. comments are appreciated .
我想清除 Electron(atom-shell) 中的缓存数据。我在 Electron 中找不到任何像 gui.App.clearCache()(node-webkit api to clear cache data) 这样的 API。如果您找到任何 api 或任何其他方式,请告诉我。评论表示赞赏。
回答by pagep
The Electron stores it's cache in these folders:
Electron 将其缓存存储在以下文件夹中:
Windows:C:\Users\<user>\AppData\Roaming\<yourAppName>\Cache
视窗:C:\Users\<user>\AppData\Roaming\<yourAppName>\Cache
Linux:/home/<user>/.config/<yourAppName>/Cache
Linux:/home/<user>/.config/<yourAppName>/Cache
OS X:/Users/<user>/Library/Application Support/<yourAppName>/Cache
操作系统:/Users/<user>/Library/Application Support/<yourAppName>/Cache
So deleting these folders can also help you. Of course this is one time solution ;-)
所以删除这些文件夹也可以帮助你。当然,这是一次性解决方案;-)
回答by Praveen kumar
You can use session.clearCacheapi.
您可以使用session.clearCacheapi。
var remote = require('remote');
var win = remote.getCurrentWindow();
win.webContents.session.clearCache(function(){
//some callback.
});
回答by goodhyun
If you want to clear any remnants of previous login sessions, you'd better use this:
如果你想清除以前登录会话的任何残余,你最好使用这个:
loginWindow.webContents.session.clearStorageData()
回答by thegnuu
We are using this in our app...
我们正在我们的应用程序中使用它...
const { app, session } = require('electron');
// ...
session.defaultSession.clearStorageData(null, (error: any) => {
// in our case we need to restart the application
// app.relaunch();
// app.exit();
});
Update for Electron 7:
Electron 7 的更新:
await session.defaultSession.clearStorageData();
回答by neel
Ans :
答:
var remote = require('remote'); var win = remote.getCurrentWindow(); win.WebContents.session.cookies.get(details, callback) // getting cookies win.WebContents.session.cookies.remove(details, callback) //deleting cookies
var remote = require('remote'); var win = remote.getCurrentWindow(); win.WebContents.session.cookies.get(details, callback) // getting cookies win.WebContents.session.cookies.remove(details, callback) //deleting cookies
for more info : http://electron.atom.io/docs/v0.29.0/api/browser-window/
更多信息:http: //electron.atom.io/docs/v0.29.0/api/browser-window/
回答by undefinederror
you could try mainWindow.webContents.clearHistory();or deleting contents in the app Cache folders (will be recreated on app run).
You can get the path with app.getPath('userData') + '/Cache'
您可以尝试mainWindow.webContents.clearHistory();或删除应用程序缓存文件夹中的内容(将在应用程序运行时重新创建)。你可以得到路径app.getPath('userData') + '/Cache'
回答by Marcelo Juan Cabrera Gutierrez
when you are developing, in developer tools go to the tab application and in clear storage and clear site data
开发时,在开发人员工具中转到选项卡应用程序和清除存储和清除站点数据

