34

During an attempt to bring an older android application into the modern world, I have come across the deprecated statement of:

websettings.setAppCacheEnabled(false)

What is the modern Androidx alternate?

callumg46
  • 471
  • 1
  • 4
  • 10

2 Answers2

28

Use this

webView.settings.cacheMode=WebSettings.LOAD_NO_CACHE

Refer : https://developer.android.com/reference/android/webkit/WebSettings

Jithish P N
  • 1,970
  • 3
  • 26
  • 39
  • what if I had `websettings.setAppCacheEnabled(true)`, what should I set now? – user924 Jul 15 '23 at 22:16
  • @user924 You can always opt-in for cache data using WebSettings.LOAD_CACHE_ONLY or .LOAD_CACHE_ELSE_NETWORK. – Joe Aug 21 '23 at 13:13
24

Alternatively, this helped me out:

webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
Antoine
  • 1,393
  • 4
  • 20
  • 26
Techy Rakshak
  • 271
  • 2
  • 6
  • 1
    what if I had `websettings.setAppCacheEnabled(true)`, what should I set now? – user924 Jul 15 '23 at 22:16
  • @user924 this line of code is not depreciated, that's why we have the new line of code that gives the same result. – Techy Rakshak Jul 17 '23 at 03:39
  • 1
    @user924 use webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); or webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); LOAD_DEFAULT does not use expired cache but LOAD_CACHE_ELSE_NETWORK does – Nero Aug 10 '23 at 12:58