Despite Apple's documentation indicating otherwise, NSURLCache
on iOS doesn't do any disk (flash) caching at all. You can subclass NSURLCache
to change the behaviour of the fetch and store operations to use the disk (like SDURLCache
does), but due to the following severe limitations of how the cache is used and implemented, this doesn't work as well as you'd expect:
NSURLConnection
doesn't even callstoreCachedResponse:forRequest:
for files over about 50KB (>= 52428 bytes, to be exact). This makes subclassingNSURLCache
pointless for our use (200KB images), because it won't even get to the cache. As a result, we have to add caching manually at a level aboveNSURLConnection
.- Even when one calls the NSURLCache's built-in
storeCachedResponse:forRequest:
manually, it only stores the response in memory if it's less than about 180KB. I tested this by calling storeCachedResponse manually and seeing that the before/aftercurrentMemoryUsage
didn't change for data lengths above about 180KB. So we have to write our own LRU memory caching too.
Has anyone else noticed these issues? Or is there something I'm missing?
FYI, I'm running iOS 4.3 in the simulator and on an iPad 2.