NSURLConnection is returning old data

后端 未结 2 1012
再見小時候
再見小時候 2021-01-03 04:49

In my application, I am loading JSON data using the NSURLConnection method, what looks like this:

NSURLRequest *request = [[NSURLRequest alloc]         


        
相关标签:
2条回答
  • 2021-01-03 05:15

    The easiest solution to prevent request caching is to add a timestamp parameter with current time at the end:

    http://example.com/api.json?my=args&timestamp=2344992923
    
    0 讨论(0)
  • 2021-01-03 05:19

    You'll need to tell the NSURLRequest to re-evaluate (if your server sends the appropriate modified headers) or not use it's cache. Here's a snippet from my JBAsyncImageView project (hint: Use NSURLRequestReloadRevalidatingCacheData or NSURLRequestReloadIgnoringLocalCacheData):

    // Create request
    self.imageRequest = [[NSURLRequest alloc] initWithURL:imageURL 
                                              cachePolicy:(self.cachesImage) ? NSURLRequestReturnCacheDataElseLoad : NSURLRequestReloadIgnoringLocalCacheData 
                                          timeoutInterval:self.downloadTimeoutInterval];
    
    // Begin download
    self.imageData = nil;
    self.imageConnection = [[NSURLConnection alloc] initWithRequest:self.imageRequest 
                                                           delegate:self 
                                                   startImmediately:YES];
    
    0 讨论(0)
提交回复
热议问题