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.