HTTP Caching Behavior
For the HTTP and HTTPS protocols, NSURLRequestUseProtocolCachePolicy
performs the following behavior:
-
If a cached response does not exist for the request, the URL loading system fetches the data from the originating source.
-
Otherwise, if the cached response does not indicate that it must be revalidated every time, and if the cached response is not stale (past its expiration date), the URL loading system returns the cached response.
-
If the cached response is stale or requires revalidation, the URL loading system makes a HEAD request to the originating source to see if the resource has changed. If so, the URL loading system fetches the data from the originating source. Otherwise, it returns the cached response.
This behavior is illustrated in Figure 1.
Figure 1 NSURLRequestUseProtocolCachePolicy decision tree for HTTP and HTTPS![Flow chart starting with “need to determine whether to return a cached response”, and then considering various factors to determine whether to return a cached response or to fetch it anew.](https://docs-assets.developer.apple.com/published/d4a7d0cbf4/46788d50-fb95-48f2-8360-b8c2a4bf1648.png)
https://developer.apple.com/documentation/foundation/nsurlrequestcachepolicy/nsurlrequestuseprotocolcachepolicy