Search code examples
iosnsurlconnectionnsurlcache

How does - [NSURLCache cachedResponseForRequest:] actually get the matching cache?


How does -[NSURLCache cachedResponseForRequest:] works? Is it works like key-value pair where the key is the content of the NSURLRequest object (which includes the NSURL object, cache policy, time out interval, HTTPBody, HTTPHeaders)? If so then if any of the above field is different then we could not retrieve the cache.

For example, assuming the NSURLRequest has everything staying the same except the HTTPBody, which one request has the body of:

{
a = 1;
}

while another request has the body of:

{
a = 2;
}

Am I be able to get the cache of former request using the latter request?


Solution

  • IIRC, only the URL is taken into account. If header or body data dfferences matter to you, you'll need to implement a custom cache. The URL Loading System Programming guide should be of some help, should you decide to go down that path.