DevPrep

All topics › Networking & APIs

HTTP caching: Cache-Control, ETag and URLCache

Middle PRO

The gist

The HTTP cache is configured by the server through response headers; the client only picks a policy. A URLSession with the .default configuration has a URLCache (memory + disk) that runs the cache logic itself: a fresh response is served with no network at all, a stale one is revalidated with a conditional request, to which the server replies 304 Not Modified with no body.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store