Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable the cache in cordova android app

I had used the Cordova 3.6.3 version for building my android app and i wnat to disable the caching of URL in cordova webview , I am using the default cordova project for that purpose and using the index.html file. I tried this but it is crashing my app

public class MyClass extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
   setContentView(R.layout.main);
    mwebview=(WebView) findViewById(R.id.appView);
    WebSettings ws=mwebview.getSettings();
    ws.setAppCacheEnabled(false);
    ws.setCacheMode(WebSettings.LOAD_NO_CACHE);
    // Set by <content src="index.html" /> in config.xml
    loadUrl(launchUrl);
    }
}
like image 288
Nishant Avatar asked Feb 07 '23 15:02

Nishant


2 Answers

cordova-disable-http-cache

Cordova plugin to completely disable caching of HTTP requests and responses.

Just type this command in your Cordova CLI:

cordova plugin add cordova-disable-http-cache

This will fetch plugin "cordova-disable-http-cache" via npm and install "cordova-disable-http-cache" for android.

It solved my problem with disabling cache in my application. My cordova version is 6.5.0.

like image 144
Vasiliy S. Avatar answered Feb 13 '23 05:02

Vasiliy S.


Cordova (due to running on top of webview) respects the nocache header, if you're able to set that in your server it should give you the same result. Plus you can control the use of the cache itself through expirations and the like.

like image 20
hdezela Avatar answered Feb 13 '23 05:02

hdezela