UIWebView cache policy, clearing cookies

Source: Internet
Author: User
Tags vars

Cache Policy Nsurlrequestcachepolicy

Nsurlrequestuseprotocolcachepolicy
The cache policy is defined in the Web protocol implementation and is used to request a specific URL. is the default URL caching policy

Specifies that the caching logic defined in the protocol implementation, if any, was used for a particular URL load request . The default policy for URL, load requests.

Nsurlrequestreloadignoringlocalcachedata

Fetching data from the server, ignoring the local cache

Specifies that the data for the URL load should is loaded from the originating source. No existing cache data should is used to satisfy a URL load request.

Nsurlrequestreloadignoringlocalandremotecachedata

Not only does the local cache data be ignored, but the intermediate network medium (such as a proxy server) is ignored to ignore the cache. Take it directly from the most original server

Specifies that isn't only should the local cache data is ignored, but so proxies and other intermediates should is Instruc Ted to disregard their caches so far as the protocol allows.

Nsurlrequestreloadignoringcachedata

was replaced by Nsurlrequestreloadignoringlocalcachedata.

Replaced by Nsurlrequestreloadignoringlocalcachedata.

Nsurlrequestreturncachedataelseload

The cached data that already exists is used to request a return, regardless of its expiration date and how long it has existed. If no corresponding cached data is requested, read from the data source

Specifies that the existing cached data should is used to satisfy the request, regardless of their age or expiration date. If There is no existing data in the cache corresponding the request, the data was loaded from the originating source.

Nsurlrequestreturncachedatadontload

The cached data that already exists is used to request a return, regardless of its expiration date and how long it has existed. If you do not request the corresponding cache data, do not go to the data source read, the request is set to fail, this situation is more used in offline mode

Specifies that the existing cache data should is used to satisfy a request, regardless of their age or expiration date. If There is no existing data in the cache corresponding to a URL of load request, no attempt is made to load the data from th e originating source, and the load is considered to has failed. This constant specifies a behavior, that's similar to an "offline" mode.

Nsurlrequestreloadrevalidatingcachedata

Cached data that already exists is validated against the data source first, and if it is not valid, it is fetched from the data source

Specifies that the existing cache data are used provided the Origin source confirms its validity, otherwise the URL is Loaded from the Origin source.

Nsurlrequestuseprotocolcachepolicy and Nsurlrequestreloadrevalidatingcachedata differences

Personal opinion, for reference only, if there is an error, please point out, this is very important to me, thank you

Nsurlrequestreloadrevalidatingcachedata is sure to verify that the cache is valid with the original data source.
Nsurlrequestuseprotocolcachepolicy is a web-based protocol that controls caching, and the head of the server that returns data has relevant information. It may return intermediate network media (such as data from a proxy server)


It is very necessary to do a local test for the cache policy.

[OBJC]View Plaincopyprint?
    1. Nsurl *weburl = [Nsurl urlwithstring:@ "Http://localhost/test.txt"];
    2. Nsurlrequest *request =[nsurlrequest requestwithurl:weburl cachepolicy:       Nsurlrequestreloadrevalidatingcachedata timeoutinterval:60];
    3. [self. Mainwebview Loadrequest:request];


Using Nsurlrequestreloadrevalidatingcachedata here, it is important to verify that the data is valid before returning the cache data.

    • Use to build two test.txt with the same name, put one to the server first.

    • Then directly modify the server's Test.txt file, add the field "-----------------------------" save, you can see the immediate effect.

    • Replace the current test.txt in the server with another test.txt, and it will take effect immediately.

With the simple verification above, Nsurlrequestreloadrevalidatingcachedata This mode is sensitive to the modification and substitution of files stored in the server.

I'm using the Appache server that comes with the Mac system.
The file directory is in/library/webserver/documents
The way to start Apache is to enter sudo apachectl start on the command line
Then enter the password, the input process command line is no display, no tube, enter and then hit enter. There is a hint: The server is already started.

Based on the information in the document, the default caching mechanism used by Initwithurl is Nsurlrequestuseprotocolcachepolicy, and the request time is 60s, and the request fails over time

Related documents
Clearing cookies

[OBJC]View Plaincopyprint?
    1. Nshttpcookie *cookie;
    2. Nshttpcookiestorage *storage = [Nshttpcookiestorage sharedhttpcookiestorage];
    3. for (cookie in [storage cookies]) {
    4. [Storage Deletecookie:cookie];
    5. }

UIWebView cache policy, clearing cookies

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.