2017-06-15 72 views
2

我不能讓Alamofire或iOS停止緩存:Alamofire無法禁用緩存

Alamofire.SessionManager.default.session.configuration.requestCachePolicy = .reloadIgnoringLocalCacheData 

URLCache.shared.removeAllCachedResponses() 

我需要禁用它,所有的請求?

也試過:

let configuration = URLSessionConfiguration.default 
configuration.urlCache = nil 
let manager = Alamofire.SessionManager(configuration: configuration) 

這給這個錯誤:

Auth request failed with error: 
Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLKey=http://localhost:8080/slow/file.json, NSLocalizedDescription=cancelled, NSErrorFailingURLStringKey=http://localhost:8080/slow/file.json} 

回答

2

這是工作:

URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil) 

然後就是Alamofire.request

0

我用URLCache.shared.removeAllCachedResponses()每個Alamofire請求之前停止緩存

+0

嗯,它不適合我... –

0

要禁用您Urlcache文件,你必須創建自定義Alamofire Managernil urlCache。

let configuration = URLSessionConfiguration.default 
configuration.urlCache = nil 
let manager = Manager(configuration: configuration) 

的更多信息,你可以找到在Apple Documenation

To disable caching, set this property to nil.

+0

經理== SessionManager?謝謝;設置SessionManager不起作用。 –

0

你不能改變一個URLSessionConfiguration具有的屬性已經被用來初始化一個URLSession,這是你的代碼示例正在做什麼。像k8mil said一樣,如果您想要這種行爲,您應該創建自己的Alamofire SessionManager,並禁用緩存。