https://developer.apple.com/documentation/foundation/urlcache
has this:
"Although URLCache instance methods can safely be called from multiple execution contexts at the same time, be aware that methods like cachedResponse(for:) and storeCachedResponse(_:for:) have an unavoidable race condition when attempting to read or write responses for the same request."
What does it mean "unavoidable"? If I put a lock (mutex / NSLock, or similar) in my wrappers on top of "cachedResponse" / "storeCachedResponse" would that avoid the mentioned race condition?
Also, what do they mean by "the same request"? A few examples below:
let url = URL(string: "https://www.apple.com")!
let req1 = URLRequest(url: url)
let req2 = req1 // perhaps "the same"
let req3 = URLRequest(url: url) // "the same"?
let req4 = URLRequest(url: req1.url!) // "the same"?
let req5 = URLRequest(url: url, cachePolicy: req1.cachePolicy, timeoutInterval: req1.timeoutInterval) // "the same"?
let req6 = URLRequest(url: url, cachePolicy: req1.cachePolicy, timeoutInterval: 1234) // "the same"?
let req7 = URLRequest(url: url, cachePolicy: .reloadIgnoringCacheData, timeoutInterval: req1.timeoutInterval) // "the same"?
assert(req1 == req2)
assert(req1 == req3)
assert(req1 == req4)
assert(req1 == req5)
assert(req1 == req6) // this is ok
assert(req1 == req7) // this fails