Node Clearing Webkit Cache

I recently discovered that it c:/Users/username/AppData/Local/AppName/Cache

contains over 100k cache files.

I read a bit and saw that the method gui.App.clearCache()

should fix this. I run this method on startup and on shutdown of the application. (after gui assignment require("nw.gui")

)

However, this doesn't seem to help. Nothing is removed.

Any ideas why this is so?

+3


source to share


3 answers


The request cache is apparently only available on global.require.cache

.

Clearing this cache manually made it work for me.



for(module in global.require.cache){
    if(global.require.cache.hasOwnProperty(module)){
        delete global.require.cache[module];
    }
}
location.reload()

      

Neither for me, nor for gui.APP.clearCache()

, nor for gui.Window.get().reloadIgnoringCache()

was.

+4


source


Go to the same problem, so I created a quick solution to fix the problem temporarily until I can rely on the native gui.App.clearCache function. This removes the entire Cache directory and recreates it asynchronously.

This requires fs-extra and works with Linux, OSX and Windows.



var customClearCache = function(){
  var dir = path.join(gui.App.dataPath, '/Cache');
  fs.remove(dir, function(err) {
    if (err) return console.error(err)
    fs.mkdirs(dir, function(err) {
      if (err) return console.error(err)
      // This is where I start my app
    });
  });
};
      

Run codeHide result


0


source


It's 2019 now and clearCache () works by adding the following:

var gui = require('nw.gui'); 
gui.App.clearCache();

      

or

nw.App.clearCache();

      

This will clear the HTTP cache in memory and the one on disk regardless of your platform. I tested it on Mac OS, but maybe there may be user rights issues on Linux.

On macOS, you can check in real time that the cache folder is cleared in

Mac HD โ–ธ Users โ–ธ youruser โ–ธ Library โ–ธ Caches โ–ธ yourapp โ–ธ Default

0


source







All Articles