今天先介紹下 類引用 剩下的會盡快補上 類引用有5個 分別是如下幾個 html
SDImageCache 圖片異步緩存web
SDWebImageDownloader 圖片異步下載 xcode
SDWebImageDownloaderOperation Class Reference 圖片異步下載操做緩存
SDWebImageManager 圖片管理app
SDWebImagePrefetcher 圖片預處理異步
1、SDImageCache 圖片異步緩存async
概述ide
SDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed asynchronous so it doesn’t add fetch
unnecessary latency to the UI.
atom
SDImageCache只要包括維護一個內存緩存和一個可選的磁盤緩存。磁盤高速緩存的寫操做被執行異步因此它不會增長沒必要要的等待時間到用戶界面。
property
屬性
@property (assign, nonatomic) NSInteger maxCacheAge 以秒爲單位 圖片保存在內存中的最長時間
maxMemoryCost property 保存在存儲器中像素的總和
maxCacheAge maxCacheSize property 在內存中可以存儲圖片的最大容量 以比特爲單位
+ sharedImageCache
建立一個新的緩存空間
– initWithNamespace:
添加一個只讀的緩存路徑
– addReadOnlyCachePath:
– storeImage:forKey:
– storeImage:forKey:toDisk:
– storeImage:recalculateFromImage:p_w_picpathData:forKey:toDisk:
– queryDiskCacheForKey:done:
– p_w_picpathFromMemoryCacheForKey:
– p_w_picpathFromDiskCacheForKey:
刪除圖片
– 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
[objc] view plain copy
[objc] view plain copy
// 清除磁盤中的緩存
[cache cleanDisk];
// 清除緩存的存儲
[cache clearMemory];
[self.tableView reloadData];
// 建立緩存實例
cache = [[SDImageCache alloc]init];
// 獲取sdwebp_w_picpath的共享單例
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);
@interface TableViewController (){
SDImageCache *cache;
}
// 異步加載圖片並緩存
[cell.p_w_picpathView sd_setImageWithURL:[NSURL URLWithString:@"http://p2.pstatp.com/thumb/1314/2834512236"] placeholderImage:[UIImage p_w_picpathNamed:@"placeho.jpg"]];