2

I am doing following to clear the cache from the WkWebView. I would like to know how do I confirm that the cache is cleared

 var request = new NSUrlRequest (webURL, NSUrlRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData, 0);

 NSUrlCache.SharedCache.RemoveAllCachedResponses ();
 NSUrlCache.SharedCache.MemoryCapacity = 0;
 NSUrlCache.SharedCache.DiskCapacity = 0;

Is there a way to print the cache when making the request

Iain Smith
  • 9,230
  • 4
  • 50
  • 61
User382
  • 864
  • 19
  • 42

1 Answers1

5

From this question looks like you do this (c# version) for iOS 9 and it will print out which records are deleted:

var websiteDataTypes = new NSSet<NSString>(new []
{
    //Choose which ones you want to remove
    WKWebsiteDataType.Cookies,
    WKWebsiteDataType.DiskCache,
    WKWebsiteDataType.IndexedDBDatabases,
    WKWebsiteDataType.LocalStorage,
    WKWebsiteDataType.MemoryCache,
    WKWebsiteDataType.OfflineWebApplicationCache,
    WKWebsiteDataType.SessionStorage,
    WKWebsiteDataType.WebSQLDatabases
});

WKWebsiteDataStore.DefaultDataStore.FetchDataRecordsOfTypes (websiteDataTypes, (NSArray records) =>
{
    for (nuint i = 0; i < records.Count; i++) {
        var record = records.GetItem<WKWebsiteDataRecord> (i);

        WKWebsiteDataStore.DefaultDataStore.RemoveDataOfTypes (record.DataTypes, 
            new[] {record}, () => {Console.Write($"deleted: {record.DisplayName}");});
    }
});

Or for iOS 8, from ShingoFukuyama/WKWebViewTips you could check the subdirectories Cookies, Caches, WebKit in the Library directory are removed.

iOS 8

After much trial and error, I've reached the following conclusion:

Use NSURLCache and NSHTTPCookie to delete cookies and caches in the same way as you used to do on UIWebView.

If you use WKProccessPool, re-initialize it.

Delete Cookies, Caches, WebKit subdirectories in the Library directory.

Delete all WKWebViews

Community
  • 1
  • 1
Iain Smith
  • 9,230
  • 4
  • 50
  • 61
  • Still the question is how to validate that the cache is cleared – User382 May 02 '16 at 20:46
  • I am having error while constructing websiteDataTypes. It says "Type Foundation.NSSet does not contain a definition for Add and no extension method Add of type Foundation.NSSet could be found – User382 May 03 '16 at 19:47