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?
source to share
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.
source to share
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
});
});
};
source to share
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
source to share