Backup Cache for UIImageView in AFNetworking

I am looking to change the default AFImageCache in the UIImageView+AFNetworking to what is on disk and which can be controlled a bit more accurately (something like NSURLCache ). Unfortunately, since UIImageView+AFNetworking is a category, not a subclass, I cannot just override af_sharedImageCache with the UIImageView sublayer OR another category.

Is there any other way to achieve this functionality without copying and pasting most of UIImageView+AFNetworking into my own subclass?

+4
source share
2 answers

The SDWebImage project provides a similar UIImageView category, but offers both in-memory caching (using NSCache) and on-disk caching (using NSFileManager). I would recommend just using this when you need to cache to disk.

The disadvantage of this implementation is that your network requests will not go through your AFHTTPClient subclass, so depending on your needs, you may need to implement your own operation queue, authentication, etc. If you're just using it for something basic, like displaying avatar images in a table, for example, this should be fine.

If this drawback bothers you, an alternative idea would be to use SDImageCache (included in the SDWebImage project) to cache images and download them yourself using AFNetworking.

Finally, note that AFNetworking has built-in support for NSURLCache , and if you create it, it will cache your images to disk. However, image caching is typically used to display a large number of images in a UIScrollView , and NSURLCache does not have enough performance for smooth scrolling.

+6
source

I have an AFNetworking fork that includes the file cache in NSCachesDirectory.

You can find it here: https://github.com/andyast/AFNetworking_FileCache There is a branch compatible with V1.3.3 if you need it.

+2
source

Source: https://habr.com/ru/post/1485903/


All Articles