I am not currently interested in changing the default caching policy Swift has on URLRequests, but I would like to know if a particular request has been cached or not. Is there a method on the URLRequest object that will tell me this?
For context, if a URLRequest has been cached, I don't want to show a loading screen (because it will load fairly quickly). But if a URLRequest hasn't been cached, I do want to show a loading screen / circle so the user isn't staring at nothing for a second or so.
CodePudding user response:
The other answer linked to the right source. But the particular method I found that worked for me was the cachedResponse method on the URLCache.shared singleton class. Passing the URLRequest object to this method will return an optional--nil if the URLRequest hasn't been cached; the value if it has.
CodePudding user response:
Is that https://developer.apple.com/documentation/foundation/url_loading_system/accessing_cached_data
what you are looking for?
