dataWithContentsOfURL缓存吗?
问题描述:
我试图找出如果dataWithContentsOfURL
缓存的内容,因此,如果在代码:dataWithContentsOfURL缓存吗?
UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[NSString stringWithFormat:@"http://testsite.com/img/%@.png"
,imgName]]]];
线将遵循:
UIImage *img2 = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[NSString stringWithFormat:@"http://testsite.com/img/%@.png"
,imgName]]]];
将需要再次去到网络上?
答
这没有被缓存。
我建议你开始使用ASIHTTPRequest或AFNetwork框架。它们允许你缓存。
如果你做NSMutableURLRequest,你有一些方法可以缓存,但不是很好。
你也应该不会,因为他们占用你的主线程中使用XWithContentOfURL,除非你使用线程或GCD,事情你会得到免费的,如果你使用上面的框架
您可以保存和使用NSData的 –
OOV ..一时刻,2个具有相同图像内容的UIImage的需求是什么?您可以在任何地方使用相同的权利? –
只有在运行时决定后续请求时才会调用img2。 URL也在运行时结束。我想知道如果我的应用程序需要两次访问相同的URL,它将再次需要网络访问。 – Ted