0

The goal is to get one URLSession to send request not directly to the network but to another URLSession. I need the default URLSession caching mechanism but want to get modified data in some cases (particularly I want to resize some images and let URLSession to cache that resized image data).

let urlRequest = SomeURLRequestChainingDecorator() //The goal
let urlRequest = URLRequest(url: url)
let (proxiedImageData, _) = try await urlSession.data(for: urlRequest) //mark 1
image = UIImage(data: proxiedImageData, scale: scale)

//mark 1:
//Need intermediate task here to do image resizing and encode back to Data before URLSession will get the response
var image = UIImage(data: originalData, scale: scale).resize()
return image.jpegData(compressionQuality: 0.5)
bodich
  • 1,708
  • 12
  • 31
  • 1
    Why don't you manually set the urlcache after processing the image locally instead? https://developer.apple.com/documentation/foundation/urlcache/1410340-storecachedresponse – Kamil.S Nov 17 '22 at 07:23
  • @Kamil.S Thanks, that was exactly what I have anded up with yesterday. I am creating CachedURLResponse from the original URLResponse and modified data. Thank you for involvement, I will add this answer here later. – bodich Nov 17 '22 at 14:34

0 Answers0