How to clear the cache data in Electron(atom shell)?

78,958

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/

Share:
78,958

Related videos on Youtube

neel
Author by

neel

Updated on December 09, 2020

Comments

  • neel
    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
      neel almost 9 years
      WebContents.session.cookies.get(details, callback)
  • Julio Guerra
    Julio Guerra about 6 years
    Is it safe removing their content?
  • Derek Pollard
    Derek Pollard about 5 years
    How does this help in an electron application?
  • Neoraptor
    Neoraptor over 4 years
    CTRL+SHIFT+I opens up the dev tools in Electron apps. This answer is one of possible solutions.
  • Trevor
    Trevor over 4 years
    Thank 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
    openwonk over 3 years
    Worked fine without the await
  • thegnuu
    thegnuu over 3 years
    Of course, I just added it to indicate that this action is async ;)
  • Nuryagdy Mustapayev
    Nuryagdy Mustapayev over 3 years
    on 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.