SDWebImage 最新版詳解

今天先介紹下 類引用  剩下的會盡快補上  類引用有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



  1. //  清除磁盤中的緩存  

  2. [cache cleanDisk];  

  3. //  清除緩存的存儲  

  4. [cache clearMemory];  

  5. [self.tableView reloadData];  

  1. //  建立緩存實例  

  2.     cache = [[SDImageCache alloc]init];  

  3.     //  獲取sdwebp_w_picpath的共享單例  

  4.     cache =  [SDImageCache sharedImageCache];  

  5.       

  6.     // 在內存緩存保留的最長時間 以秒爲單位計算 爲了檢測 設置爲5秒  

  7.     cache.maxCacheAge = 30;  

  8.     //  在內存中可以存儲圖片的最大容量 以比特爲單位 這裏設爲1024 也就是1M  

  9.     cache.maxCacheSize = 1024;  

  10.     //  保存在存儲器中像素的總和  

  11.     cache.maxMemoryCost = 1000;  

  12.       

  13.       

  14.     //  下載  

  15.     // 建立實例  

  16.     downloaderImage = [SDWebImageDownloader sharedDownloader];  

  17.     //  設置下載的用戶名和密碼  

  18.     downloaderImage.username = @"yun";  

  19.     downloaderImage.password = @"0628";  

  20.     //  設置下載超時時間  

  21.     downloaderImage.downloadTimeout = 5;  

  22.       

  23.     //  當前的下載量 只讀屬性  

  24.     NSInteger downloader  = [downloaderImage currentDownloadCount];  

  25.     NSString *downloaderCount = [NSString stringWithFormat:@"%ld",(long)downloader];  

  26.     NSLog(@"downloaderCount = %@",downloaderCount);  

  27.       

  28.       

  29.     NSInteger macDownloader = [SDWebImageDownloader sharedDownloader].maxConcurrentDownloads;  

  30.     NSLog(@",(long)macDownloader = %ld",(long)macDownloader);  

  1. @interface TableViewController (){  

  2.     SDImageCache *cache;  

  3. }  

[objc] view plain copy
  1. //  異步加載圖片並緩存  

  2.    [cell.p_w_picpathView sd_setImageWithURL:[NSURL URLWithString:@"http://p2.pstatp.com/thumb/1314/2834512236"] placeholderImage:[UIImage p_w_picpathNamed:@"placeho.jpg"]];  

相關文章
相關標籤/搜索