Node Webkit clear cache

六月ゝ 毕业季﹏ 提交于 2019-12-03 16:27:54

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

Clearing that 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 the gui.APP.clearCache() nor the gui.Window.get().reloadIgnoringCache() had any effect for me.

Ran into the same issue so I created a quick solution to solve 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 should work on 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
    });
  });
};

It is now 2019 and clearCache() does function 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 whatever your platform. I have tested it on Mac OS but maybe there can be user permission issues on Linux.

On MacOS, you can check in real time that the cache folder is emptied at ‎⁨

Mac HD⁩ ▸ ⁨Users⁩ ▸ youruser ▸ ⁨Library⁩ ▸ ⁨Caches⁩ ▸ ⁨yourapp ▸ ⁨Default⁩

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!