我试图弄清楚 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,如果您使用上述框架,您就可以免费获得这些东西
关于ios - dataWithContentsOfURL 是否缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12688853/