I'm tying to save some response to URLCache:
var cache: URLCache = URLCache(memoryCapacity: 4 * 1024 * 1024, diskCapacity: 10 * 1024 * 1024, diskPath: nil)
request.response { (dataResponse) in
guard let response = dataResponse.response,
let data = dataResponse.data,
let request = request.request else { return }
let cachedResponse = CachedURLResponse(response: response, data: data, userInfo: nil, storagePolicy: .allowed)
print(cachedResponse)
self.cache.storeCachedResponse(cachedResponse, for: request)
print(self.cache.cachedResponse(for: request))
}
But output is nil:
NSCachedURLResponse: 0x6000000053e0
nil
However size of cache used memory was increasing.
I've tried to create my own cache or using URLCache.shared instance
But response was always nil
Also I've tried to use another method of URLCache, that saves CachedResponse for task, and it save it only in case when task was in running state, but not in suspended state:
cache.storeCachedResponse(cachedResponse, for: task)
I'm really can't understand, whats happens inside this class.
P.S. I've read all article about URLCache, like these: http://nshipster.com/nsurlcache/ https://blackpixel.com/writing/2012/05/caching-and-nsurlconnection.html