Note that there are some explanatory texts on larger screens.

plurals
  1. PONSURLCache Problem with cache response
    primarykey
    data
    text
    <p>I'm writing an iPhone application, one of it's tabs is a twitter feed, i'm parsing twitter xml and putting it nicely inside a table view. In case there is no internet connection I would like to show cache results of the last time we had internet connection and the tables were updated. I'm using NSURLCache for that like so:</p> <pre><code>NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:xmlLink] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60]; NSURLCache *sharedCache = [NSURLCache sharedURLCache]; NSCachedURLResponse *response = [sharedCache cachedResponseForRequest:theRequest]; if (response) { NSLog(@"Got Response"); } else { NSLog(@"Didn't got Response"); } self.objectFeedConnection = [[[NSURLConnection alloc] initWithRequest:theRequest delegate:self startImmediately:YES] autorelease]; </code></pre> <p>I can see that for the first time NSLog outputs "Didn't got response" since it's the first time visiting this website (<a href="http://www.twitter.com/.." rel="nofollow noreferrer">http://www.twitter.com/..</a>.) I can also see that the response is being cached, since i implemented the willCacheResponse method which is being called after the initWithRequest was launched, like so:</p> <pre><code> - (NSCachedURLResponse *) connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse { NSLog(@"willCache Reponse"); NSCachedURLResponse *newCachedResponse = nil; if ([[[[cachedResponse response] URL] scheme] isEqual:@"http"]) { newCachedResponse = [[[NSCachedURLResponse alloc] initWithResponse:[cachedResponse response] data:[cachedResponse data] userInfo:nil storagePolicy:[cachedResponse storagePolicy]] autorelease]; } return newCachedResponse; } </code></pre> <p>The second time i visit this site i can clearly see that NSLog outputs "Got Response" which means that there was a cache hit, hence willCacheResponse should <strong>not</strong> be called again, but for some strange reason it is called again and again and does not pull the information out of the cache, instead it try to cache it again.</p> <p>Any idea what causing this issue ?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload