Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a big advantage to using SDWebImage over AFNetworking for image loading?

SDWebImage claims that AFNetworking doesn't cache the image itself but just the HTTP response, so SDWebImage is faster in recalling the image from cache and presenting it.

If I wanted to use purely AFNetworking, is such a claim, true or not, really something that is noticeable performance-wise? Is it something I should be wary of?

like image 966
Doug Smith Avatar asked Jan 05 '14 00:01

Doug Smith


2 Answers

It's not true.

If you look at the code, you can see that the category UIImageView+AFNetworking cache the UIImage (using NSCache and the urlRequest as the key). The cache isn't written to disk though.

like image 90
toasted_flakes Avatar answered Nov 15 '22 21:11

toasted_flakes


SDWebImage has much more control over image caching. It can cache to disk or memory.

AFNetworking relies on NSURLCache to persist images between app launches (and it's not very reliable), but it's great if you just need to cache during one run.

Both solutions cache a UIImage object in memory during the lifetime of the app. This is important because caching the NSData representation isn't fast enough to load images smoothly when scrolling through a table view.

Summary: AFNetworking's solution is simpler and will work for most use cases. If you need finer control, or disk caching, use SDWebImage instead of modifying AFNetworking's implementation.

like image 37
Aaron Brager Avatar answered Nov 15 '22 19:11

Aaron Brager