SDImageCache 图片异步缓存
SDWebImageDownloader 图片异步下载
SDWebImageDownloaderOperation Class Reference 图片异步下载操作
- SDWebImageManager 图片管理
-
- SDWebImagePrefetcher 图片预处理
- 一、SDImageCache 图片异步缓存
概述
-
SDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed asynchronous so it doesn’t add
-
unnecessary latency to the UI.
-
SDImageCache只要包括维护一个内存缓存和一个可选的磁盘缓存。磁盘高速缓存的写操作被执行异步所以它不会增加不必要的等待时间到用户界面。
-
property
属性 -
@property (assign, nonatomic) NSInteger maxCacheAge 以秒为单位 图片保存在内存中的最长时间
-
maxMemoryCost property 保存在存储器中像素的总和
maxCacheAge maxCacheSize property 在内存中能够存储图片的最大容量 以比特为单位
+ sharedImageCache -
创建一个新的缓存空间
– initWithNamespace: -
添加一个只读的缓存路径
– addReadOnlyCachePath:
– storeImage:forKey:
– storeImage:forKey:toDisk:
– storeImage:recalculateFromImage:imageData:forKey:toDisk:
– queryDiskCacheForKey:done:
– imageFromMemoryCacheForKey:
– imageFromDiskCacheForKey: -
删除图片
– removeImageForKey:
– removeImageForKey:withCompletion:
– removeImageForKey:fromDisk:
– removeImageForKey:fromDisk:withCompletion:
– clearMemory 清除缓存
– clearDiskOnCompletion:
– clearDisk 清除磁盘
– cleanDiskWithCompletionBlock: block回调 在清除磁盘后的操作
– cleanDisk 清除磁盘
– getSize 获取缓存的大小 比特 如果想要获取M 可以与1024相除
– getDiskCount 在磁盘中缓存图片的个数
– calculateSizeWithCompletionBlock:
– diskImageExistsWithKey:completion:
– diskImageExistsWithKey:
– cachePathForKey:inPath:
– defaultCachePathForKey: 默认缓存的路径
-
[objc] view plain copy
- @interface TableViewController (){
- SDImageCache *cache;
- }
[objc] view plain copy- // 创建缓存实例
- cache = [[SDImageCache alloc]init];
- // 获取sdwebimage的共享单例
- cache = [SDImageCache sharedImageCache];
- // 在内存缓存保留的最长时间 以秒为单位计算 为了检测 设置为5秒
- cache.maxCacheAge = 30;
- // 在内存中能够存储图片的最大容量 以比特为单位 这里设为1024 也就是1M
- cache.maxCacheSize = 1024;
- // 保存在存储器中像素的总和
- cache.maxMemoryCost = 1000;
- // 下载
- // 创建实例
- downloaderImage = [SDWebImageDownloader sharedDownloader];
- // 设置下载的用户名和密码
- downloaderImage.username = @"yun";
- downloaderImage.password = @"0628";
- // 设置下载超时时间
- downloaderImage.downloadTimeout = 5;
- // 当前的下载量 只读属性
- NSInteger downloader = [downloaderImage currentDownloadCount];
- NSString *downloaderCount = [NSString stringWithFormat:@"%ld",(long)downloader];
- NSLog(@"downloaderCount = %@",downloaderCount);
- NSInteger macDownloader = [SDWebImageDownloader sharedDownloader].maxConcurrentDownloads;
- NSLog(@",(long)macDownloader = %ld",(long)macDownloader);
[objc] view plain copy- // 清除磁盘中的缓存
- [cache cleanDisk];
- // 清除缓存的存储
- [cache clearMemory];
- [self.tableView reloadData];
-
[objc] view plain copy
- // 异步加载图片并缓存
- [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://p2.pstatp.com/thumb/1314/2834512236"] placeholderImage:[UIImage imageNamed:@"placeho.jpg"]];