HTTP Cache, where have you been all my life?

Yesterday I learned about the built-in support for HTTP cache in URLSession. How had I missed out on this? There are so many frameworks and libs out there that implement image caching systems, but this great functionality is already built into Foundation.

This post by Alexander Grebenyuk does a good job of laying it all out.

In my current project I need this to cache profile images.

Most of what I had to do to get HTTP cache working was to set the cache policy for my image requests. (Cache policy can be configured per session or per individual request.)

request.cachePolicy = .returnCacheDataElseLoad

(Note: This policy ignores validation in favor of always returning the cached value. We have a separate mechanism to signal profile image changes.)

Crepecakes

When we first arrived in Switzerland last August, I couldn’t figure out where to buy baking soda/powder. So I used to make unleavened pancakes, which we jokingly dubbed “crepe-cakes”. Now my son specifically asks for them this way. (For the record, it’s “Backpulver”)