大型图像缓存来自afnetworking



我正在使用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]; 

我注意到所有响应图像都会从该方法自动缓存到磁盘上。我也希望在我的应用中选择该选项。所有缓存图像的大小约为150kb。但是,当我下载大约2MB大小的图像时,这些图像不会自动缓存到磁盘上。

为什么要缓存小尺寸的图像&大型图像没有缓存?我是否使用错误的方法来缓存afnetworking?

任何人都可以使用afnetworking给我解决缓存2MB图像的解决方案。

谢谢

问题不是afnetworking,而是与nsurlcache有关。默认情况下,NSURLCACHE不会高速缓存文件,而不是高速缓存大小的10%(不确定确切的百分比)。

但增加缓存大小将有所帮助:

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

最新更新