ios - How to disable caching in Alamofire -


when send request twice alamofire same response i'm expecting different one. wondering if because of cache, , if i'd know how disable it.

swift 3, alamofire 4

my solution was:

creating extension alamofire:

extension alamofire.sessionmanager{     @discardableresult     open func requestwithoutcache(         _ url: urlconvertible,         method: httpmethod = .get,         parameters: parameters? = nil,         encoding: parameterencoding = urlencoding.default,         headers: httpheaders? = nil)//you can pass urlrequest.cachepolicy parameter         -> datarequest     {         {             var urlrequest = try urlrequest(url: url, method: method, headers: headers)             urlrequest.cachepolicy = .reloadignoringcachedata // <<== cache disabled             let encodedurlrequest = try encoding.encode(urlrequest, with: parameters)             return request(encodedurlrequest)         } catch {             // todo: find better way handle error             print(error)             return request(urlrequest(url: url(string: "http://example.com/wrong_request")!))         }     } } 

and using it:

alamofire.sessionmanager.default             .requestwithoutcache("https://google.com/").response { response in                 print("request: \(response.request)")                 print("response: \(response.response)")                 print("error: \(response.error)")         } 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -