I’ve the next code.
let customCache: URLCache = {
let cacheSizeMemory = 512 * 1024 * 1024
let cacheSizeDisk = 512 * 1024 * 1024
return URLCache(memoryCapacity: cacheSizeMemory, diskCapacity: cacheSizeDisk, diskPath: "serverTest")
}()
let customSession: URLSession = {
// Create a customized URLSessionConfiguration
let sessionConfiguration = URLSessionConfiguration.default
sessionConfiguration.urlCache = customCache
sessionConfiguration.requestCachePolicy = .useProtocolCachePolicy
// Create a customized URLSession with the configuration
let customSession = URLSession(configuration: sessionConfiguration)
return customSession
}()
Listed here are a number of of the headers for my response:
< content-length: 93828673
< cache-control: public, max-age=300
I anticipate due to these headers the machine to cache the response for five minutes. Nonetheless that is not what is going on.
Now once I change these variables to the next the cache does work:
let cacheSizeMemory = 512 * 1024 * 1024 * 5
let cacheSizeDisk = 512 * 1024 * 1024 * 5
This makes completely no sense to me as a result of the response is just 93,828,673 bytes, which is way lower than the utmost cache measurement of 536,870,912 bytes.
Does Apple set some sort of buffer or one thing the place a single response can solely take up x% of the cache or one thing like that? I am unable to discover any documentation that may recommend that, however it’s the one rationalization I can consider.