Question

We are building an iOS app that uses AFNetworking to connect to a server running Tornado. The server includes the header Cache-Control: private, max-age=900 in the response. When running the server on my local machine, I can tell that AFNetworking uses the cached values because there are no requests received by the server on repeated requests from the app. When we deploy the same Tornado server to the test machine, each request from the app results in a request received on the server, ignoring the cached value.

The only difference between the two setups are the URL of the server and the fact that the test server is accessed over a HTTPS connection, while the localhost uses HTTP. Does HTTPS affect the caching by AFNetworking, and if so, how can we get AFNetworking to respect the cache header?

Was it helpful?

Solution

Not sure if its gonna be any help but here it is anyway: AFNetworking uses NSURLConnection which uses NSURLCache shared cache. AFNetworking absolutely transparent in cache regard and doesn't do anything specific. My requests are https and were caching just fine.

Cache-Control response directives allow an origin server to override the default cacheability of a response: private Indicates that all or part of the response message is intended for a single user and MUST NOT be cached by a shared cache. This allows an origin server to state that the specified parts of the response are intended for only one user and are not a valid response for requests by other users. A private (non-shared) cache MAY cache the response. http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.1

If acceptable try to change policy to public . Log headers on response from the app and look at your cache.db and see if in fact something is caching there.

Try to configure shared cache - something along the lines of

int cacheSizeMemory = 1*1024*1024; // 4MB
int cacheSizeDisk = 100*1024*1024; // 100MB
[[NSURLCache sharedURLCache] setMemoryCapacity:cacheSizeMemory];
[[NSURLCache sharedURLCache] setDiskCapacity:cacheSizeDisk];

Another good read about this here http://petersteinberger.com/blog/2012/nsurlcache-uses-a-disk-cache-as-of-ios5/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top