Spajk
Spajk

Reputation: 21

Android WebView cache aggressiveness

I developed a web app which I then embedded into an Android WebView. The problem I am encountering is that the WebView is barely doing any caching of assets compared to desktop Chrome for example.

As you can see, WebView barely caches anything ( only 2 entries here ), while desktop Chrome caches all of them.

WebView caching: WebView caching Chrome Desktop caching: Chrome Desktop caching

What could be the cause of this and is there something I can do to make more things cached?

I have tried enabling AppCache with settings.setAppCacheEnabled(true), but that hasn't changed anything.

EDIT: I believe that the cache is limited to 20MB, I have reduced the size of my web app to be under 20MB and now it's cached nicely. I have yet to find a way to increase that size limit.

Upvotes: 2

Views: 4033

Answers (2)

VoD
VoD

Reputation: 11

I believe in the source code this is hard-coded to be 20MB and so unfortunately I don't think it can be increased.

static const int kMaximumCacheSizeBytes = 20 * 1024 * 1024;

https://android.googlesource.com/platform/external/webkit/+/jb-mr2-release/Source/WebKit/android/WebCoreSupport/WebCache.cpp

Upvotes: 1

snachmsm
snachmsm

Reputation: 19223

try to set setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK) on these WebView settings object

Use cached resources when they are available, even if they have expired.

Upvotes: 1

Related Questions