Ios-NSURLRequest: the Cache Policy and NSURLConnection send asynchronous requests,

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.