如何判断NSURLConnection是否缓存了某个图像?

时间:2012-08-07 22:32:12

标签: ios cocoa-touch ipad nsurlconnection nsurlcache

我如何找出UIImage是否已经使用NSURLConnection进行缓存?

示例:

if([NSURLCache containsObject:[UIImage imageNamed@"testPic.png"]]){
NSLog(@"item already cached!");
}

显然上面的代码不起作用,但你明白了......

谢谢!

1 个答案:

答案 0 :(得分:0)

您必须保存请求的副本,然后再询问sharedCache:

- (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request

返回的对象中包含大量内容,包括数据对象。