title: Universal Windows 10 WebView - how to clear/disable cache?
body: <p>I am having a lot of trouble clearing the WebView cache in my UWP app.</p>
  
  <p>If I edit the content of a JS file linked from my HTML page, I can't get the change into my app unless I re-install the app.</p>
  
  <p>The static <a href="https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.webview.cleartemporarywebdataasync.aspx" rel="nofollow">WebView.ClearTemporaryWebDataAsync()</a> method doesn't seem to work.</p>
  
  <p>I have also tried adding headers to the request to disable caching:</p>
  
  <pre><code>private void reloadPage()
  {
      string url = getUrl();
      HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, new Uri(url));
      request.Headers.Add("Cache-Control", "no-cache, no-store, must-revalidate");
      request.Headers.Add("Pragma", "no-cache");
      myWebView.NavigateWithHttpRequestMessage(request);
  }
  </code></pre>
  
  <p>I also tried the following, on a punt (I'm not sure if this affects the WebView's caching behaviour), but still no joy:</p>
  
  <pre><code>private void onWebviewLoaded(object sender, RoutedEventArgs e)
  {
      Windows.Web.Http.Filters.HttpBaseProtocolFilter myFilter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
      myFilter.CacheControl.WriteBehavior = Windows.Web.Http.Filters.HttpCacheWriteBehavior.NoCache;
      myFilter.CacheControl.ReadBehavior = Windows.Web.Http.Filters.HttpCacheReadBehavior.Default;
  
      WebView.ClearTemporaryWebDataAsync().AsTask().Wait();
      reloadPage();
  }
  </code></pre>
  
  <p>Any help would be very much appreciated!</p>
  
  <p><strong>EDIT (14/12/15):</strong>
  I have found that adding headers to the request (as in the first code example above) <em>does</em> work, but only if this has been in place for the lifetime of the app, since install. Which makes sense, as it's just saying not to cache this particular request - it could still use an old cached version.</p>
  
  <p>This works as a cludge for now, but it would be much nicer to be able to make use of caching (e.g. for the duration of an app session), then later clear the cache (e.g. on next startup).</p>
  
  <p><strong>EDIT (14/07/16):</strong> The above approach doesn't seem to bear out. Caching behaviour seems to be erratic in the webview...</p>
  
  <p>On a clean install of the app, I can see changes to CSS/JS files with absolutely NO code to clear/disable cache. Then at some seemingly arbitrary point, files seem to be cached, and I cannot clear them from the cache.</p>