How to clear the cache data in Electron(atom shell)?
Solution 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 ;-)
Solution 2
You can use session.clearCache api.
var remote = require('remote');
var win = remote.getCurrentWindow();
win.webContents.session.clearCache(function(){
//some callback.
});
Solution 3
If you want to clear any remnants of previous login sessions, you'd better use this:
loginWindow.webContents.session.clearStorageData()
Solution 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();
Solution 5
Answer:
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/
Related videos on Youtube
neel
Updated on December 09, 2020Comments
-
neel over 3 years
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 .
-
neel almost 9 yearsWebContents.session.cookies.get(details, callback)
-
-
Julio Guerra about 6 yearsIs it safe removing their content?
-
Derek Pollard about 5 yearsHow does this help in an electron application?
-
Neoraptor over 4 yearsCTRL+SHIFT+I opens up the dev tools in Electron apps. This answer is one of possible solutions.
-
Trevor over 4 yearsThank you, this is helpful if you just need to quickly clear the cache without writing code for it for a one time thing. The original question wasn't clear that it needed a code solution or a 1 time solution.
-
openwonk over 3 yearsWorked fine without the
await
-
thegnuu over 3 yearsOf course, I just added it to indicate that this action is async ;)
-
Nuryagdy Mustapayev over 3 yearson Windows you get cache path by
const process = require('process');
process.env.APPDATA + "\\"+ app.getName() + "\\Cache";
I am not sure will it work on other platforms.