Post

Replies

Boosts

Views

Activity

URLSession and URLCache not working as expected
For a GET request which is consistently the same, I'm returning in the response this response header. Cache-Control: max-age=3600, private I'm creating a URLSession with this configuration. Basically, ensuring my cache is large. The URLSession persists throughout the life of the app and all requests go through it.  var configuration = URLSessionConfiguration.default           let cache = URLCache(memoryCapacity: 500_000_000,                                diskCapacity: 1_000_000_000)         configuration.urlCache = cache         configuration.requestCachePolicy = .useProtocolCachePolicy I create a data task with the completion handler: let task = session.dataTask(with: request) { data, response, error in //... my response handling code here } task.resume() There isn't anything complicated or unusual I'm doing. I've used this code for years, and I'm now trying to optimise some calls with a caching policy. So I have 2 issues: Requests that have no-cache policy are still being saved into the URLCache. Which I've confirmed by looking into URLCache.shared.cachedResponse . Why is it caching them when the response explicitly states no-cache policy and I've told the session to use the protocol policy. On the request where I do want to use the cache, when I call session.dataTask on subsequent times, it never fetches from the cache. It always hits the server again - which I can confirm from the server logs. What piece of this am I missing here?
1
0
2.3k
Mar ’22
Xcode Cloud builds failing intermittently with network issues
My Xcode Cloud builds are failing intermittently with network issues when download SPM dependencies. In particular today was the facebook SDK binaries, which does exist as I tested separately:. Kind of annoying, as there isn't anything I can do to resolve this I think. failed downloading 'https://github.com/facebook/facebook-ios-sdk/releases/download/v14.0.0/FBSDKCoreKit-Static_XCFramework.zip' which is required by binary target 'FBSDKCoreKit': downloadError("Error Domain=NSURLErrorDomain Code=-1005 \"The network connection was lost.\" UserInfo={NSURLSessionDownloadTaskResumeData={length = 7045, bytes = 0x62706c69 73743030 d4010203 04050607 ... 00000000 00001adf }, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDownloadTask <9ABA1AD6-45B3-48E7-BC6C-A8CD11DA5E14>.<3>, _NSURLErrorRelatedURLSessionTaskErrorKey=(\n    \"LocalDownloadTask <9ABA1AD6-45B3-48E7-BC6C-A8CD11DA5E14>.<3>\"\n), NSLocalizedDescription=The network connection was lost., NSErrorFailingURLStringKey=https://objects.githubusercontent.com/github-production-release-asset-2e65be/738491/36b15867-27f1-4ac5-8c79-fffc1a9cfd4a?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220705%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220705T074918Z&X-Amz-Expires=300&X-Amz-
9
5
2.3k
Jul ’22