Search code examples
iosswiftalamofirensurlcache

Alamofire unable disable caching


I can not get Alamofire or iOS to stop caching:

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

or

URLCache.shared.removeAllCachedResponses()

I need to disable it for all requests?

Also tried:

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

This give this error:

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}

Solution

  • This is working:

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

    And then just Alamofire.request