To cache images to temporary storage in Swift, we can use the built-in URLCache class of URLSession.
main.swift259 chars6 lines
Then, when making requests with URLSession, we can use a URLSessionConfiguration
object that includes the cache policy in order to enable caching for our requests.
main.swift616 chars18 lines
With this setup, any subsequent requests for the same image (with the same URL) through our URLSession will be served from the cache rather than making a new network request.
gistlibby LogSnag