问题
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 .
回答1:
The Electron stores it's cache in these folders:
Windows:C:\Users\<user>\AppData\Roaming\<yourAppName>\Cache
Linux:/home/<user>/.config/<yourAppName>/Cache
OS X:/Users/<user>/Library/Application Support/<yourAppName>/Cache
So deleting these folders can also help you. Of course this is one time solution ;-)
回答2:
You can use session.clearCache api.
var remote = require('remote');
var win = remote.getCurrentWindow();
win.webContents.session.clearCache(function(){
//some callback.
});
回答3:
If you want to clear any remnants of previous login sessions, you'd better use this:
loginWindow.webContents.session.clearStorageData()
回答4:
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:
await session.defaultSession.clearStorageData();
回答5:
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
for more info : http://electron.atom.io/docs/v0.29.0/api/browser-window/
回答6:
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'
回答7:
when you are developing, in developer tools go to the tab application and in clear storage and clear site data
来源:https://stackoverflow.com/questions/31446782/how-to-clear-the-cache-data-in-electronatom-shell