Skip to content

Instantly share code, notes, and snippets.

@mazharulbelal
Created June 23, 2022 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mazharulbelal/316704ff0e0256da276f9f0cb8f55d07 to your computer and use it in GitHub Desktop.
Save mazharulbelal/316704ff0e0256da276f9f0cb8f55d07 to your computer and use it in GitHub Desktop.
Alamofire Cache policy setup
private func apiCalling(url: String,method: HTTPMethod,parameters: [String : Any]?,header: HTTPHeaders?, cachePolicy: Bool, completion: @escaping COMPLETION_HANDLER<Data>) {
let configuration = URLSessionConfiguration.default
configuration.requestCachePolicy = . reloadIgnoringLocalAndRemoteCacheData
var req = URLRequest(url: URL(string: url)!)
req.httpMethod = method.rawValue
req.headers = API_HEADER
req.cachePolicy = cachePolicy ? .returnCacheDataDontLoad : .reloadIgnoringLocalAndRemoteCacheData
AF.request(req)
.validate(statusCode: 200..<300)
.responseJSON { (response) in
completion(response.data,response.error)
print("========> API: \(url)")
print("========> API: \(response)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment