Reputation: 1085
Apple has supported disk caching as of iOS 5.0. I was using a home-rolled solution before, but I'm testing NSURLCache
in hopes of finally using it since I've seen strange behavior in the past.
One of the more perplexing issues I'm having is that cachedResponseForRequest:
returns expired requests. I've been testing by setting forward the clock on the iPhone I'm using. Parsing the headers clearly shows that the device time is ahead of the expiration date.
I'm willing to accept that there may be a background task that prunes expired requests on a regular interval. I have done tests where I actually wait to see if the request expires "naturally", and it doesn't.
Did Apple just fail to implement cache invalidation correctly?
I'm testing using a Charles proxy. It's a tough problem and I don't envy anyone who has to implement cache invalidation, but iOS is supposed to be a mature SDK by now.
Upvotes: 6
Views: 848
Reputation: 3537
There are two http caching mechanisms: expiration and validation.
If a response has not expired, the client can serve it from the cache without making a request to the server.
If it has expired the client can make conditional requests using the If-Match
or If-Modified-Since
header entries.
If the server responds with 304 Not Modified
, the client can use the data from the cache even if it has expired.
For more details have a look at http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html.
Upvotes: 1