[![CI Status](http://img.shields.io/travis/Roberto Sartori/ImageCacher.svg?style=flat)](https://travis-ci.org/Roberto Sartori/ImageCacher)
ImageCacher helps you to easily cache web images from a given URL using Core Data as persistent storage framework, GCD for background fetching and blocks for asynch operations.
ImageCacher strategy is straightforward: you ask for an image by specifying its URL, the singleton class then:
- search the image into an internal memory structure as first attempt, it will call the handler immediatly before return with source = ICCacheSourceMemory
- otherwise it will try to fetch the image in background form the caching database, it will call the handler in case of success at the end of the fetching operation (executed in background) with source = ICCacheSourceLocal
- otherwise download the image from the URL, save it to the caching database and will call the handler with source = ICCacheSourceWeb
- if URL is invalid or a fatal error occurs the handler il called with source = ICCacheSourceUnknown
The common usage pattern is the following:
[[ICImageCacher shared] getImageWithURL:<myurl> withCompletionHandler^(UIImage *image ,tICCacheSource source) {
switch (source) {
case ICCacheSourceMemory:
// image has been found into memory, this block is called WITHIN getImageWithURL execution
break;
case ICCacheSourceLocal:
// image has been found into local caching database, this block is called later
break;
case ICCacheSourceWeb:
// image has been downloaded for the first time, , this block is called later.
// Next time this url will be fetched from memory or from local cache
break;
case ICCacheSourceUnknown:
// image not found ad not downloaded (an error should has been encountered)
break;
}
}];
ImageCacher is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "ImageCacher"
Roberto Sartori, roberto.sartori@gmail.com
ImageCacher is available under the MIT license. See the LICENSE file for more info.