Is there a framework for image caching on iOs?

痞子三分冷 提交于 2019-12-04 01:57:52

问题


I'm already using AFNetworking for async image download. I was wondering if there's a way for storing on disk or Core Data, should I investigate SDWebImage for that? Or you would suggest to have a custom solution. Basically I would like to have a very transparent way to get images from a url, so first look for them in a NSCache, if not found look on disk (or Core Data)l if not found again download async. Thanks for any idea


回答1:


SDWebImage has proven to be a really solid implementation of async image fetching and caching.

If you're using your web images for buttons or imageviews you can even call the -(void)setImageWithURL:(NSURL *)url methods that will check the cache, get the image for you and if it's not there, it will async download it and store it in the cache before setting it.

If you need the images for some other stuff, you can still benefit from this library by calling :

SDWebImageManager *manager = [SDWebImageManager sharedManager];

// Remove in progress downloader from queue
[manager cancelForDelegate:self];

[manager downloadWithURL:yourURL delegate:self options:0];

and retrieving the image later on the delegate method:

- (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UIImage *)image
{
    // Do something with the image
}

Note that

- (void)downloadWithURL:(NSURL *)url delegate:(id<SDWebImageManagerDelegate>)delegate options:(SDWebImageOptions)options

does check the cache before attempting to download, so it is safe to call this every time you need an image.




回答2:


Give this a try...

https://github.com/rs/SDWebImage




回答3:


You could have a look to EGOImage which basically makes asynchronous calls and caching of images on the file system.



来源:https://stackoverflow.com/questions/8703877/is-there-a-framework-for-image-caching-on-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!