LBCache 1.0.7

LBCache 1.0.7

测试已测试
Language语言 Obj-CObjective C
许可证 MIT
Released最后发布2017 年 4 月

Lucian Boboc 维护。



LBCache 1.0.7

LBCache 是一个异步图像缓存框架,用于 iOS。

如何使用

UIImageView+LBCategory.h

  • 这个 UIImageView 分类提供在服务器上设置图像位置的 URL 字符串的选项;
  • 图像将在后台异步下载;
  • 图像将被保存在缓存目录的磁盘上;

有 3 个选项可供使用

  • LBCacheImageOptionsDefault - 默认选项将首先搜索缓存,如果找不到图像,则从网络下载。
  • LBCacheImageOptionsReloadFromWeb - 重新加载选项将始终从网络下载图像,即使它已经存在于缓存中。
  • LBCacheImageOptionsLoadOnlyFromCache - 缓存选项将只搜索缓存
  __weak UIImageView *weakImgView = cell.imgView;    
  [cell.imgView setImageWithURLString: self.array[indexPath.row] placeholderImage: nil options: LBCacheImageOptionsDefault progressBlock:^(NSUInteger percent) {
      NSLog(@"percent: %ld",percent);
  } completionBlock:^(UIImage * image, NSError * error) {
      dispatch_async(dispatch_get_main_queue(), ^{
          weakImgView.image = image;
      });
  }];

LBCacheManager.h

这个类由 UIImageView 分类用于下载,但您也可以直接使用它。您可以使用 LBCacheManager 中的方法从磁盘或图像缓存的路径位置获取 UIImage 对象。

  • imagePathLocationForURLString: - 一个包含图像在磁盘上保存的本地路径位置的字符串,如果未找到 URLString 的图像则为 nil。
  • imageForURLString: - 与 UIImageView+LBCategory 相同,直接在缓存(内存或磁盘)中搜索 UIImage,如果未找到则返回 nil。
  __weak UIImageView *weakImgView = self.imgView;
  [[LBCacheManager sharedInstance] downloadImageFromURLString: self.array[indexPath.row] options: LBCacheImageOptionsDefault progressBlock:^(NSUInteger percent) {
      NSLog(@"percent: %ld",percent);
  } completionBlock:^(UIImage * image, NSError * error) {
      dispatch_async(dispatch_get_main_queue(), ^{
          weakImgView.image = image;
      });
  }];
  
  // you can also get the image from the disk using the urlString.
  UIImage *image = [[LBCacheManager sharedInstance] imageForURLString: urlString];

  // you can get the image path where it is cached.
  NSString *imgPath = [[LBCacheManager sharedInstance] imagePathLocationForURLString:urlString];

NSString+LBCategory.h

您可以使用这个类分类从字符串获得哈希值。

  • 有 3 个选项可用,MD5, SHA1 和 SHA256

可用的方法

  • lbHashMD5 - 创建一个 MD5 哈希
  • lbHashSHA1 - 创建一个 SHA1 哈希
  • lbHashSHA256 - 创建一个 SHA256 哈希
  • lbHashWithType: - 使用可用选项之一创建一个哈希
  // you can use lbHashMD5, lbHashSHA1 or lbHashSHA256 method to get the specific hash from a string.
  NSString *hashStr = [urlString lbHashSHA1];
  
  // you can also use the lbHashWithType method and pass an option HashTypeMD5, HashTypeSHA1 or HashTypeSHA256
  NSString *hashStr = [urlString lbHashWithType: HashTypeMD5];

licensing

此内容根据 MIT 许可证发布 https://github.com/lucianboboc/LBCache/blob/master/LICENSE.md

请享受!