从networking化大图像caching

我正在使用AFNetworking从互联网下载一些图像到我的应用程序。 我使用这个代码来下载这些图像,

AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_linkString[indexPath.item]]]]; requestOperation.responseSerializer = [AFImageResponseSerializer serializer]; [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 150, 150)]; _imageView.image = responseObject; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Image error: %@", error); }]; [requestOperation start]; 

我注意到,所有的响应图像都从这个方法自动caching到磁盘。 我也想在我的应用程序的选项。 所有caching的图像大小约为150kb。 但是当我下载一张2MB大小的图像时,这些图像不会自动caching到磁盘上。

为什么小图像caching和大尺寸图像不会被caching? 我在AFNetworking中使用错误的方式caching图像?

任何一个可以给我一个解决scheme,以caching2MB图像使用AFNetworking以及….

谢谢

问题不在于AFNetworking,而在于NSURLCache。 默认情况下,NSURLCache不会caching大于10%的文件(不知道确切百分比是多less)。

但增加caching大小将有助于:

 [[NSURLCache sharedURLCache] setMemoryCapacity:(20*1024*1024)]; [[NSURLCache sharedURLCache] setDiskCapacity:(200*1024*1024)];