IOS Caching Policy

I am connecting to NSURL and I need to create a request to bypass the entire caching policy. I have seen examples such as:

NSURLRequest *request = [NSURLRequest requestWithURL:baseURL cachePolicy:0 timeoutInterval:10]; self.urlConnection = [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease]; 

May I ask what the cache policy 0 refers to? Tried to find what the number represents, but I don't get the answer I need. Thank you :)

+7
source share
3 answers

you should take a look at the NSURLRequestCachePolicy enum, here 0 means NSURLRequestUseProtocolCachePolicy, which means that NSURLRequest will not download data from the server every time.

 enum { NSURLRequestUseProtocolCachePolicy = 0, NSURLRequestReloadIgnoringLocalCacheData = 1, NSURLRequestReloadIgnoringLocalAndRemoteCacheData =4, NSURLRequestReloadIgnoringCacheData = NSURLRequestReloadIgnoringLocalCacheData, NSURLRequestReturnCacheDataElseLoad = 2, NSURLRequestReturnCacheDataDontLoad = 3, NSURLRequestReloadRevalidatingCacheData = 5 }; typedef NSUInteger NSURLRequestCachePolicy 
+6
source

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/Reference/Reference.html

NSURLRequestUseProtocolCachePolicy = 0

Indicates that the caching logic defined in the protocol implementation, if any, is used for a specific request to load a URL. This is the default policy for URL load requests.

Example. If you use HTTP, the HTTP header fields will be evaluated to decide that caching should not be used.

The correct policy in your case:

NSURLRequestReloadIgnoringLocalCacheData p>

+2
source

According to this article: http://blackpixel.com/blog/2012/05/caching-and-nsurlconnection.html if you are using NSURLRequestUseProtocolCachePolicy and the server does not return any expiration or maximum age, cache time interval by The default is 6 - 24 hours. Therefore, be careful with this condition. It is better to use the maximum age or expiration when using NSURLRequestUseProtocolCachePolicy.

+1
source

All Articles