I am using the code below to set the caching policy of my URLSession via URLConfiguration.
if appDelegateObj.configuration == nil {
appDelegateObj.configuration = URLSessionConfiguration.default
}
if self.apiType == ServerRequest.API_TYPES_NAME.API1 {
if appDelegateObj.forceReload == true {
appDelegateObj.configuration?.urlCache = nil
appDelegateObj.configuration?.requestCachePolicy = .reloadIgnoringLocalCacheData
}else{
appDelegateObj.configuration?.requestCachePolicy = .returnCacheDataElseLoad
}
}else{
appDelegateObj.configuration?.requestCachePolicy = .reloadIgnoringLocalCacheData
}
session = URLSession(configuration: appDelegateObj.configuration!, delegate: nil, delegateQueue: nil)
The problem I am having is that I am getting the cached response back even after setting the
appDelegateObj.configuration?.urlCache = nil
The only way I am able to get fresh data is via using
appDelegateObj.configuration?.requestCachePolicy = .reloadIgnoringLocalCacheData
What am I doing wrong ? I need a way to clear all the cached data for the app.
I have tried using
URLCache.shared.removeAllCachedResponses()
but that too isn't working.