AFNetworking/AFNetworking — pull request #956 by OliverLetterer (2013-04-27 21:10:10+00:00)
Title: [Proposal] Image processing

I think the current caching behavior of `AFImageCache` can result in a bad user experience. Let's consider the following scenario:

* An app is displaying an avatar of an authenticated user.
* The developer of the app is setting this image for an image view via `UIImageView (AFNetworking)`.
* If the user changes this image with let's say a POST request, he expects this image in the image view to change.
* The `AFImageCache` will pick up the old cached image and the user will not see the image change.

One thing I changed with this pull request is to always request the image from the server. Furthermore, I added an extra caching layer in `AFImageCache` by querying the shared `NSURLCache` to grab a `NSCachedURLResponse` and load the image from there if available.

Consequences of doing this have been mentioned in #909 in case a success block has been passed into `-[UIImageView setImageWithURLRequest:placeholderImage:success:failure:]`. The main reason for passing in a success block here would be image processing. Since the image processing has been done by the developer and not AFNetworking, we were not able to apply a cached image directly to the image view. The developer would rather need to process the cached image __and__ the response image (and maybe cache processed images) on his own. There are lot's of things one can get wrong here which will result in a bad UX (like processing images on the main thread). Processing and caching of images seems like a pretty repetitive task to me and I think (hope) this justifies a merge into AFNetworking or the future UI extensions for AFNetworking.

What this pull request includes:

* The `UIImageView (AFNetworking)` category exposes a new public method `-[UIImageView addImageFilter:]` and handles image processing and caching.
* AFNetworking takes care of all the heavy lifting:
* Image processing is being cached in memory and on disk for optimal user experience.
* Image processing is being done, if necessary, on a background dispatch queue.
* I added a new class `AFImageFilter` which is an abstract superclass handling image processing. There are _private_ concrete subclasses of `AFImageFilter` for resizing images and processing images with a custom block: `+[AFImageFilter imageFilterWithTargetSize:]` and `+[AFImageFilter imageFilterWithUniqueKey:block:]`.

I would love to here what you guys think of this.