AlamoFire Ignore Cache-Control Headers

£可爱£侵袭症+ 提交于 2019-11-30 05:26:59

To ignore the cached data, you need to set the cachePolicy on the NSURLRequest before using Alamofire to start it.

let URL = NSURL(string: "https://my_url_path...")!
let URLRequest = NSMutableURLRequest(URL: URL)
URLRequest.cachePolicy = .ReloadIgnoringCacheData

Alamofire.request(URLRequest)
    .response { response in
        print(response)
    }

Setting the cachePolicy on the URL request always overrides the value set on the NSURLSessionConfiguration.

By default, the NSURLSessionConfiguration cache policy is set to .UseProtocolCachePolicy which will honor the Cache-Control header values.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!