CodexBloom - Programming Q&A Platform

implementing WKWebView cache not clearing correctly after iOS 17 update

πŸ‘€ Views: 53 πŸ’¬ Answers: 1 πŸ“… Created: 2025-07-07
ios wkwebview caching swift Swift

I'm having trouble with After updating to iOS 17, I've noticed that my WKWebView is not clearing its cache as expected when I call `clearCache()` from my app. I am using the following code to clear the cache: ```swift let websiteDataTypes = Set([WKWebsiteDataTypeMemoryCache, WKWebsiteDataTypeDiskCache]) let dateFrom = Date(timeIntervalSince1970: 0) WKWebsiteDataStore.default().removeData(ofTypes: websiteDataTypes, modifiedSince: dateFrom) { print("Cache cleared") } ``` Despite seeing the "Cache cleared" print statement in the console, the web pages are still loading from the cache. I've also tried adding a delay before reloading the content, and I even used `invalidate()` on the `WKWebView` instance. Here’s the reloading code: ```swift webView.load(URLRequest(url: myURL)) ``` I initially thought the scenario might be related to caching headers but after checking, the server correctly sets no-cache headers. I also verified that other caching solutions in my app are functioning correctly. Has anyone else encountered issues with WKWebView cache management post-iOS 17 update? What steps can I take to ensure that the cache is properly cleared so that my users always see the latest content? This is part of a larger web app I'm building. Thanks in advance!