ImageCacher 帮助您使用 Core Data 作为持久化存储框架,GCD 进行后台获取和 blocks 进行异步操作来轻松地从给定 URL 缓存网页图片。
ImageCacher 的策略很简单:您通过指定图片的 URL 来请求图片,然后单例类会首先尝试在内部内存结构中搜索图像
常用的使用模式如下所示
[[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;
}
}];
Roberto Sartori,
ImageCacher 在 MIT 许可协议下提供。有关更多信息,请参阅 LICENSE 文件。
许可协议