如何在再次启动脱机应用程序时使用javascript清除缓存

时间:2023-01-20 22:16:24

I need a help to clear cache using Javascript, Is it possible to clear cache using Javascript?.

我需要一个帮助来使用Javascript清除缓存,是否可以使用Javascript清除缓存?

I have developed a Offline Chrome application using Javascript & Node WebKit. When using this application, the cache sizes increasing more day by day.

我使用Javascript和Node WebKit开发了一个离线Chrome应用程序。使用此应用程序时,缓存大小日益增加。

So I want to delete cache directory or clearing cache from AppData/Local/MyAPP.1.0 whenever I'm starting application.

因此,每当我启动应用程序时,我都希望从AppData / Local / MyAPP.1.0中删除缓存目录或清除缓存。

Kindly help me to clear the cache using Javascript (related solution).

请帮我用Javascript(相关解决方案)清除缓存。

Please let me know, if you need any information on this.

如果您需要任何相关信息,请告诉我。

Thanks in advance.

提前致谢。

3 个解决方案

#1


1  

Try this, It might works

试试这个,它可能会奏效

require("nw.gui").App.clearCache();

#2


1  

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:

我总是禁用磁盘缓存,因为我发现它减慢了一切;即使在我写的浏览器中,如果你想要禁用它也意味着不会有任何垃圾要清理,请在你的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.

注意:以上是DUMMY驱动器/路径,不存在以杀死缓存。

#3


0  

Use this recursive function to delete all files from AppData/Local/{MyAPP.1.0}/

使用此递归函数从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

使用获取AppData文件夹路径

var path = require("nw.gui").App.dataPath;

Get AppData folder path using

使用获取AppData文件夹路径

deleteFolderRecursive(path);

#1


1  

Try this, It might works

试试这个,它可能会奏效

require("nw.gui").App.clearCache();

#2


1  

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:

我总是禁用磁盘缓存,因为我发现它减慢了一切;即使在我写的浏览器中,如果你想要禁用它也意味着不会有任何垃圾要清理,请在你的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.

注意:以上是DUMMY驱动器/路径,不存在以杀死缓存。

#3


0  

Use this recursive function to delete all files from AppData/Local/{MyAPP.1.0}/

使用此递归函数从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

使用获取AppData文件夹路径

var path = require("nw.gui").App.dataPath;

Get AppData folder path using

使用获取AppData文件夹路径

deleteFolderRecursive(path);