NSURLConnection is returning old data

我的未来我决定 提交于 2019-11-30 15:20:18

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];

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!