react-native-clear-app-cache icon indicating copy to clipboard operation
react-native-clear-app-cache copied to clipboard

Delete cache dir only

Open joaopiopedreira opened this issue 7 years ago • 2 comments

Hi and thank you for this package. I wonder if you could add an option to clear only the cache directory (and not the documents directory). Thank you!

joaopiopedreira avatar Feb 03 '19 10:02 joaopiopedreira

@joaopiopedreira I looked into library and it deletes files and cache directory contents. I just skipped file file directory content deletion by commenting the below line from the ClearCacheModule.java:

public void clearCache() {

        getReactApplicationContext().deleteDatabase("webview.db");
        getReactApplicationContext().deleteDatabase("webview.db-shm");
        getReactApplicationContext().deleteDatabase("webview.db-wal");
        getReactApplicationContext().deleteDatabase("webviewCache.db");
        getReactApplicationContext().deleteDatabase("webviewCache.db-shm");
        getReactApplicationContext().deleteDatabase("webviewCache.db-wal");
        //清除数据缓存
       // clearCacheFolder(getReactApplicationContext().getFilesDir(), System.currentTimeMillis()); // Comment this line to skip file content deletion
        clearCacheFolder(getReactApplicationContext().getCacheDir(), System.currentTimeMillis());
        //2.2版本才有将应用缓存转移到sd卡的功能
        if (isMethodsCompat(android.os.Build.VERSION_CODES.FROYO)) {
            clearCacheFolder(getExternalCacheDir(getReactApplicationContext()), System.currentTimeMillis());
        }

    }

KPS250 avatar Feb 10 '19 16:02 KPS250

Hi @KPS250, sorry for my late reply, only saw this now. Thank you for your comment above, very helpful. Would you point me in the right direction for iOS too? Cheers

joaopiopedreira avatar Sep 21 '19 19:09 joaopiopedreira