Search code examples
iosswiftxcodensurlcache

How to clear cache for a URL in URLCache.shared?


Is it possible to clear the URL Cache for just one url and not the whole cache? I have already tried this put it does not seem to do anything.

let url = URL(string: "https://example.com")!
        let request = URLRequest(url: url)
        URLCache.shared.removeCachedResponse(for: request)

Solution

  • You can try make request to some url with different cache policy like reloadRevalidatingCacheData which will delete all cache for this url.