ios - NSURLSessionConfiguration 和 NSMutableURLRequest 缓存策略的区别

标签 ios swift

我正在使用代码:

let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
configuration.requestCachePolicy = NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData
let session = NSURLSession(configuration: configuration)
let request = NSMutableURLRequest(URL: url)
request.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData
request.HTTPMethod = "POST"
request.HTTPBody = bodyData
let dataTask = session.dataTaskWithRequest(request) { (data: NSData?, response: NSURLResponse?, error: NSError?) in 
    //... 
}

我想知道这两者之间有什么区别,以及必须使用哪一个。

configuration.requestCachePolicy = NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData
request.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData

谢谢。

最佳答案

NSURLSessionConfiguration sets the properties at NSURLSession which can be overridden by NSURLRequest object.

正如这里的回答: https://stackoverflow.com/a/33316897/3238178

关于ios - NSURLSessionConfiguration 和 NSMutableURLRequest 缓存策略的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39106541/

相关文章:

ios - 无法一次异步下载多个 AWS S3 图像

swift - Swift 上的高阶函数

ios - 如何提高导航栏主标题的位置?

ios - 为什么我的 NSNotification 多次调用它的观察者?

调整大小后 iOS 表格 View 单元格无法正确显示

ios - Gmail 身份验证未返回到应用程序

ios - 向 GMSMapView 添加手势识别器以获得 .begin/.ended/.change 手势

swift - 如何在 forEach 循环中传递变量函数

ios - 在 Mobile Safari 可见的 WKUIWebView 中写入一个 cookie

ios - 滑动删除不适用于 TableVIewCell?