Reputation: 4069
I have a Xamarin.Forms app with a feature using WebView
. It opens a simple web page.
Every time I open a webpage in it, app's storage data size increases. I check it on Android/Settings/App info/Storage. My app size is ~15 MB, but after opening some pages, it goes to 50 MB and so on. What is it doing? Caching? Or...? How can I disable it?
Upvotes: 2
Views: 1701
Reputation: 14760
I assume that it is the cache of the WebView
. Unfortunately, the Cache of the Forms WebView is not configurable. So you have to write a custom renderer and disable it on the native view. Add this class to your Android Project.
[assembly: ExportRenderer(typeof(WebView), typeof(NoChacheWebViewRenderer))]
namespace MyApp.Droid.Renderer
{
public class NoChacheWebViewRenderer : WebViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (Control == null) return;
Control.ClearCache(true);
Control.Settings.SetAppCacheEnabled(false);
Control.Settings.CacheMode = CacheModes.NoCache;
}
}
}
Upvotes: 6