Universal Windows 10 WebView - how to clear / disable cache?

I'm having trouble clearing the WebView cache in a UWP application.

If I edit the contents of the JS file associated with my HTML page, I cannot get the change in my application unless I reinstall the application.

The static method of WebView.ClearTemporaryWebDataAsync () does not seem to work.

I also tried adding headers to the request to disable caching:

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);
}

I also tried the following: on punt (I'm not sure if this affects the behavior of WebView caching), but still there is no joy:

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();
}

Any help would be greatly appreciated!

EDIT (14/12/15): , ( ) , , . , , - .

, (, ), (, ).

EDIT (14/07/16): , , . - ...

CSS/JS , / . -, , , , , .

+4
4

, , :

await WebView.ClearTemporaryWebDataAsync();
        Windows.Web.Http.Filters.HttpBaseProtocolFilter myFilter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
        var cookieManager = myFilter.CookieManager;

        HttpCookieCollection myCookieJar = cookieManager.GetCookies(new Uri("http://www.msftncsi.com/ncsi.txt"));
        foreach (HttpCookie cookie in myCookieJar)
        {
            cookieManager.DeleteCookie(cookie);
        }
+2

, , URL- (url + "? =" + sometimestamphere)

+1

webview :

mainWebView.Refresh();

, - , . , "mainWebView_NavigationCompleted()"?

0

css UWP, . ProcessMon , UWP- .css .js Windows 10: C:\Users\\AppData\Local\Packages\microsoft.windows.authhost.sso.p_8wekyb3d8bbwe\AC\INetCache\Q8IHZDMV. -, . , , , processmon ( SysInternals) UWP, , , UWP . .

0

Source: https://habr.com/ru/post/1613485/


All Articles