Reputation: 1378
I need a help to clear cache using Javascript, Is it possible to clear cache using Javascript?.
I have developed a Offline Chrome application using Javascript & Node WebKit. When using this application, the cache sizes increasing more day by day.
So I want to delete cache directory or clearing cache from AppData/Local/MyAPP.1.0 whenever I'm starting application.
Kindly help me to clear the cache using Javascript (related solution).
Please let me know, if you need any information on this.
Thanks in advance.
Upvotes: 0
Views: 1180
Reputation: 61
I always disable disk cache because I find it slows everything down; even in the browser I wrote, so if you want to disable it which also means that there won't be any garbage to clean up, use this setting in your package.json:
"chromium-args": "--disk-cache-dir=W:/abc --media-cache-dir=W:/abc --disk-cache-size=1 --media-cache-size=1",
NB: The above are DUMMY drives/paths that don't exist to kill the cache.
Upvotes: 2
Reputation: 1301
Use this recursive function to delete all files from AppData/Local/{MyAPP.1.0}/
deleteFolderRecursive:function(path) {
var fs = require("fs");
if( fs.existsSync(path) ) {
try{
fs.readdirSync(path).forEach(function(file) {
var curPath = path + "/" + file;
if(fs.statSync(curPath).isDirectory()) {
try{
deleteFolderRecursive(curPath);
}catch(e){
console.log(e);
}
} else {
try{
fs.unlinkSync(curPath);
}catch(e){
console.log(e);
}
}
});
fs.rmdirSync(path);
}catch(e){
console.log(e);
}
}
}
Get AppData folder path using
var path = require("nw.gui").App.dataPath;
Get AppData folder path using
deleteFolderRecursive(path);
Upvotes: 0