Remove Cache form NSURLSession call

Does anyone know how I remove cache from the following NSURLSession call? Tthe call below doesn’t bring back the updated son.


let endpoint: String = "https:/whatever.com/jsonfile.json


let session = NSURLSession.sharedSession()

let url = NSURL(string: endpoint)!

session.dataTaskWithURL(url, completionHandler: { ( data: NSData?, response: NSURLResponse?, error: NSError?) -> Void in

/

guard let realResponse = response as? NSHTTPURLResponse where

realResponse.statusCode == 200 else {

print("Not a 200 response")

return

}

You can control caching in three ways:

  • If it doesn’t make sense to cache the response at all, you can configure your server to specify that via the various cache control headers in the HTTP response it sends to your client.

  • If you create your task from an NSURLRequest rather than using the NSURL convenience method, you can create the request with a specific cache policy. Alternatively, you can create an NSMutableURLRequest and set the cache policy via the

    cachePolicy
    .
  • If you create your own NSURLSession, which is generally a good idea, you can set the default cache policy via the

    requestCachePolicy
    property of the NSURLSessionConfiguration object you use to create the session.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Remove Cache form NSURLSession call
 
 
Q