Alex Rivera | Logout

How to enforce caching in AFNetworking despite cache headers

Asked 2012-07-11T19:11:30.757
11

I want to enforce caching in AFNetworking even when cache header is Cache-Control:·private there are no other cache-relevant headers, I understand it will be a time-based cache and I do not have a problem with that.

Please advise even if it's beyond AFNetworking scope.

I am making an iOS 5 iPad app and here are the header files from the XML files I'm trying to cache:

HTTP/1.1·200·OK(CR)(LF)
Cache-Control:·private(CR)(LF)
Content-Type:·text/xml;·charset=utf-8(CR)(LF)
Server:·Microsoft-IIS/7.5(CR)(LF)
X-AspNet-Version:·2.0.50727(CR)(LF)
X-Powered-By:·ASP.NET(CR)(LF)
Date:·Wed,·11·Jul·2012·18:42:27·GMT(CR)(LF)
Connection:·close(CR)(LF)
Content-Length:·20464(CR)(LF)
(CR)(LF)

Thanks in advance.

Edit
Report

1 Answer

0

When you create NSURLRequest (+ requestWithURL:cachePolicy:timeoutInterval: or – initWithURL:cachePolicy:timeoutInterval:), you can set cachePolicy of it with the following value.

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

More detail about cachePolicy can be found here.

answered 2013-04-18T01:44:53.577

Your Answer