Ios-NSURLRequest: the Cache Policy and NSURLConnection send asynchronous requests,
An example of the method Cache Policy below NSURLRequest
[NSURLRequest requestWithURL: url cachePolicy: policy timeoutInterval: 1]
NSURLRequestUseProtocolCachePolicy = 0, default Cache Policy
NSURLRequestReloadIgnoringLocalCacheData = 1. Ignore local cache data and directly load network data. The advantage is that data can be updated in real time.
NSURLRequestReturnCacheDataElseLoad = 2. Use cached data to ignore its expiration time. Data is loaded from the source only when no cached version is available.
NSURLRequestReturnCacheDataDontLoad = 3. The cached data is returned. If no cached data exists, the request fails.
The default cache policy is described as follows:
If the requested cache response does not exist, the URL loading system loads data directly from the source;
Otherwise, if the cache response does not explicitly indicate that each request must be re-verified, if the response cache does not expire, the URL loading system will return the cached data.
If the cached response expires or needs to be verified again, the URL loading system sends a HEAD request to the source end to check whether the resource has changed. If it changes, the URL loading system extracts data from the origin. Otherwise, it returns the cached response.
Add
Attributes in NSURLResponse
The URL returned by the URL server is the same as the requested URL in most cases, but sometimes there may be redirection.
File Type of the MIMEType binary data
ExpectedContentLength the length of the downloaded object
TextEncodingName text encoding name
SuggestedFilename the name of the recommended file to be saved on the server
NSHTTPURLResponse attributes
StatusCode status code
All response header information of allHeaderFields