SDWebImage源码解读 二(下载图片)

说道用sdWebImage下载图片,那就先简单介绍下SDWebImage中下载图片的几个工具类了。SDWebImageManager是SDWebImage的核心类,他有两个属性SDImageCache *imageCache(图片缓存)、 SDWebImageDownloader *imageDownloader(图片下载)和一个代理id <SDWebImageManagerDelegate> delegate。

1、协议SDWebImageManagerDelegate

@protocol SDWebImageManagerDelegate <NSObject>

@optional

/**
 * Controls which image should be downloaded when the image is not found in the cache.
 * 控制在缓存中找不到图像时应下载的图像。
 *
 * @param imageManager The current `SDWebImageManager`  当前的“ SDWebImageManager”,也就是当前的图片管理类
 * @param imageURL     The url of the image to be downloaded    要下载图片的URL
 *
 * @return Return NO to prevent the downloading of the image on cache misses. If not implemented, YES is implied.
 也就是判断缓存中有没有图片,控制是否去下载图片


  这个方法就是判断本地缓存中是否有某个url的图片,根据是否存在返回YES/NO
 */

- (BOOL)imageManager:(nonnull SDWebImageManager *)imageManager shouldDownloadImageForURL:(nullable NSURL *)imageURL;

/**
 * Controls the complicated logic to mark as failed URLs when download error occur.
 * 控制发生下载错误时将复杂的逻辑标记为失败的URL。
 * If the delegate implement this method, we will not use the built-in way to mark URL as failed based on error code;
 * 如果委托实现此方法,则不会基于错误代码使用内置方法将URL标记为失败;
 @param imageManager The current `SDWebImageManager` 当前的“ SDWebImageManager”
 @param imageURL The url of the image 这个图片的URL
 @param error The download error for the url 这个url下载出现错误的error
 @return Whether to block this url or not. Return YES to mark this URL as failed. 是否阻止该URL。

这个方法的作用是,判断某个url是否已经被标记过为下载失败,被标记失败的url将不会被下载图片,直接返回错误

 */
- (BOOL)imageManager:(nonnull SDWebImageManager *)imageManager shouldBlockFailedURL:(nonnull NSURL *)imageURL withError:(nonnull NSError *)error;


/**
 * Allows to transform the image immediately after it has been downloaded and just before to cache it on disk and memory.
 * 允许在下载图像之后立即转换图像,然后再将其缓存在磁盘和内存中。
 * NOTE: This method is called from a global queue in order to not to block the main thread.
 * 注意:为了不阻塞主线程,从全局队列中调用此方法。
 *
 *
 * @param imageManager The current `SDWebImageManager`
 * @param image        The image to transform
 * @param imageURL     The url of the image to transform
 *
 * @return The transformed image object.
 * 
 *
 * 该方法的作用是,在下载完图片后,首先做的是将图片赋值,显示到屏幕上之后再将图片保存到缓存和磁盘中
 */
- (nullable UIImage *)imageManager:(nonnull SDWebImageManager *)imageManager transformDownloadedImage:(nullable UIImage *)image withURL:(nullable NSURL *)imageURL;

@end

2、SDImageCache

SDImageCache提供了对图片的内存缓存、异步磁盘缓存、图片缓存查询等功能,下载过的图片会被缓存到内存,也可选择保存到本地磁盘,当再次请求相同图片时直接从缓存中读取图片,从而大大提高了加载速度。在SDImageCache中,内存缓存是通过 NSCache的子类AutoPurgeCache来实现的;磁盘缓存是通过 NSFileManager 来实现文件的存储(默认路径为/Library/Caches/default/com.hackemist.SDWebImageCache.default),是异步实现的。

解读SDWebImage提供的方法

#pragma mark - Properties - 属性

/**
 * Cache Config object - storing all kind of settings 
 * 缓存配置对象-存储所有类型的设置
 */
@property (nonatomic, nonnull, readonly) SDImageCacheConfig *config;

/**
 * The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory.
 * 内存中图像缓存的最大“总成本”。 代价函数是内存中保留的像素数。,其实就是内存最大容量
 */
@property (assign, nonatomic) NSUInteger maxMemoryCost;

/**
 * The maximum number of objects the cache should hold.
 * 缓存应容纳的最大对象数。和NSCache相关的
 */
@property (assign, nonatomic) NSUInteger maxMemoryCountLimit;

#pragma mark - Singleton and initialization - 单例和初始化

/**
 * Returns global shared cache instance 
 *
 * @return SDImageCache global instance 
 *
 * -- 返回单例
 */
+ (nonnull instancetype)sharedImageCache;

/**
 * Init a new cache store with a specific namespace - 初始化具有特定名称空间的新缓存存储
 *
 * @param ns The namespace to use for this cache store - 用于此缓存存储的名称空间
 * 
 * 使用指定的命名空间实例化一个新的缓存存储
 */
- (nonnull instancetype)initWithNamespace:(nonnull NSString *)ns;

/**
 * Init a new cache store with a specific namespace and directory - 初始化具有特定名称空间和目录的新缓存存储
 *
 * @param ns        The namespace to use for this cache store - 用于此缓存存储的名称空间
 * @param directory Directory to cache disk images in - 用于缓存磁盘映像的目录
*  使用指定的命名空间实例化一个新的缓存存储和目录
 */
- (nonnull instancetype)initWithNamespace:(nonnull NSString *)ns
                       diskCacheDirectory:(nonnull NSString *)directory NS_DESIGNATED_INITIALIZER;

#pragma mark - Cache paths - 缓存路径

/**
 *  图片缓存目录
 */
- (nullable NSString *)makeDiskCachePath:(nonnull NSString*)fullNamespace;

/**
 * Add a read-only cache path to search for images pre-cached by SDImageCache - 添加只读缓存路径以搜索SDImageCache预缓存的图像
 * Useful if you want to bundle pre-loaded images with your app - 如果您想将预加载的图像与应用捆绑在一起,则很有用
 *
 * @param path The path to use for this read-only cache path - 用于此只读缓存路径的路径
 *  添加只读的缓存路径  
 */
- (void)addReadOnlyCachePath:(nonnull NSString *)path;

#pragma mark - Store Ops - 商店运营

/**
 * Asynchronously store an image into memory and disk cache at the given key. - 以给定的密钥将映像异步存储到内存和磁盘缓存中。
 *
 * @param image           The image to store - 要存储的图像
 * @param key             The unique image cache key, usually it's image absolute URL - 唯一的图片缓存键,通常是图片的绝对URL
 * @param completionBlock A block executed after the operation is finished - 操作完成后执行的块
 */
- (void)storeImage:(nullable UIImage *)image
            forKey:(nullable NSString *)key
        completion:(nullable SDWebImageNoParamsBlock)completionBlock;

/**
 * Asynchronously store an image into memory and disk cache at the given key. - 以给定的密钥将映像异步存储到内存和磁盘缓存中。
 *
 * @param image           The image to store
 * @param key             The unique image cache key, usually it's image absolute URL
 * @param toDisk(到磁盘)         Store the image to disk cache if YES - 如果是,将映像存储到磁盘缓存
 * @param completionBlock A block executed after the operation is finished
 */
- (void)storeImage:(nullable UIImage *)image
            forKey:(nullable NSString *)key
            toDisk:(BOOL)toDisk
        completion:(nullable SDWebImageNoParamsBlock)completionBlock;

/**
 * Asynchronously store an image into memory and disk cache at the given key. - 以给定的密钥将映像异步存储到内存和磁盘缓存中。
 *
 * @param image           The image to store
 * @param imageData       The image data as returned by the server, this representation will be used for disk storage - 服务器返回的图像数据,此表示形式将用于磁盘存储
 *                        instead of converting the given image object into a storable/compressed image format in order - 而不是按顺序将给定的图像对象转换为可存储/压缩的图像格式
 *                        to save quality and CPU - 节省质量和CPU
 * @param key             The unique image cache key, usually it's image absolute URL - 唯一的图片缓存键,通常是图片的绝对URL
 * @param toDisk          Store the image to disk cache if YES
 * @param completionBlock A block executed after the operation is finished
 */
- (void)storeImage:(nullable UIImage *)image
         imageData:(nullable NSData *)imageData
            forKey:(nullable NSString *)key
            toDisk:(BOOL)toDisk
        completion:(nullable SDWebImageNoParamsBlock)completionBlock;

/**
 * Synchronously store image NSData into disk cache at the given key.
 * 将映像NSData同步存储到给定键的磁盘缓存中。
 *
 * @param imageData  The image data to store
 * @param key        The unique image cache key, usually it's image absolute URL
 */
- (void)storeImageDataToDisk:(nullable NSData *)imageData forKey:(nullable NSString *)key;

#pragma mark - Query and Retrieve Ops - 查询和检索操作

/**
 *  Async check if image exists in disk cache already (does not load the image)
 *  异步检查磁盘高速缓存中是否已存在映像(不加载映像)
 *  
 *  @param key             the key describing the url
 *  @param completionBlock the block to be executed when the check is done.
 *  @note the completion block will be always executed on the main queue
 *  完成块将始终在主队列上执行
 */
- (void)diskImageExistsWithKey:(nullable NSString *)key completion:(nullable SDWebImageCheckCacheCompletionBlock)completionBlock;

/**
 *  Sync check if image data exists in disk cache already (does not load the image)
 *  同步检查磁盘缓存中是否已存在映像数据(不加载映像)
 *    
 *  @param key             the key describing the url 描述网址的键
 */
- (BOOL)diskImageDataExistsWithKey:(nullable NSString *)key;

/**
 *  Query the image data for the given key synchronously.
 *  同步查询给定键的图像数据。
 *
 *  @param key The unique key used to store the wanted image
 *  @return The image data for the given key, or nil if not found.
 *  如果找不到图片返回nil,找的情况下返回该图片
 */
- (nullable NSData *)diskImageDataForKey:(nullable NSString *)key;

/**
 * Operation that queries the cache asynchronously and call the completion when done.
 * 异步查询缓存并在完成时调用完成的操作。
 *
 * @param key       The unique key used to store the wanted image
 * @param doneBlock The completion block. Will not get called if the operation is cancelled
 *
 * @return a NSOperation instance containing the cache op - 一个包含缓存操作的NSOperation实例
 * 
 *这个方法是在缓存中查询对应key的数据
 */
- (nullable NSOperation *)queryCacheOperationForKey:(nullable NSString *)key done:(nullable SDCacheQueryCompletedBlock)doneBlock;

/**
 * Operation that queries the cache asynchronously and call the completion when done.
 * 异步查询缓存并在完成时调用完成的操作。
 *
 * @param key       The unique key used to store the wanted image
 * @param options   A mask to specify options to use for this cache query
 * @param doneBlock The completion block. Will not get called if the operation is cancelled
 *
 * @return a NSOperation instance containing the cache op
 * 同上,增加了options参数
 */
- (nullable NSOperation *)queryCacheOperationForKey:(nullable NSString *)key options:(SDImageCacheOptions)options done:(nullable SDCacheQueryCompletedBlock)doneBlock;

/**
 * Query the memory cache synchronously.
 * 同步查询内存缓存。 
 *
 * @param key The unique key used to store the image
 * @return The image for the given key, or nil if not found.
 */
- (nullable UIImage *)imageFromMemoryCacheForKey:(nullable NSString *)key;

/**
 * Query the disk cache synchronously.
 * 同步查询磁盘缓存。
 *
 * @param key The unique key used to store the image
 * @return The image for the given key, or nil if not found.
 */
- (nullable UIImage *)imageFromDiskCacheForKey:(nullable NSString *)key;

/**
 * Query the cache (memory and or disk) synchronously after checking the memory cache.
 * 检查内存缓存后,同步查询缓存(内存和/或磁盘)。
 *
 * @param key The unique key used to store the image
 * @return The image for the given key, or nil if not found.
 */
- (nullable UIImage *)imageFromCacheForKey:(nullable NSString *)key;

#pragma mark - Remove Ops - 删除操作

/**
 * Remove the image from memory and disk cache asynchronously
 * 异步从内存和磁盘缓存中删除映像
 *
 * @param key             The unique image cache key
 * @param completion      A block that should be executed after the image has been removed (optional) 删除图像后应执行的Block,可选参数
 */
- (void)removeImageForKey:(nullable NSString *)key withCompletion:(nullable SDWebImageNoParamsBlock)completion;

/**
 * Remove the image from memory and optionally disk cache asynchronously
 * 从内存和可选的磁盘高速缓存中异步删除映像
 * 
 * @param key             The unique image cache key
 * @param fromDisk        Also remove cache entry from disk if YES - 如果传入YES,还从磁盘中删除缓存条目
 * @param completion      A block that should be executed after the image has been removed (optional)
 */
- (void)removeImageForKey:(nullable NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(nullable SDWebImageNoParamsBlock)completion;

#pragma mark - Cache clean Ops - 缓存清理操作

/**
 * Clear all memory cached images 
 * 清除所有内存缓存的图像
 */
- (void)clearMemory;

/**
 * Async clear all disk cached images. Non-blocking method - returns immediately.
 * 异步清除所有磁盘缓存的映像。 非阻塞方法-立即返回。
 * @param completion    A block that should be executed after cache expiration completes (optional) 可选Block参数,缓存过期后的回调
 */
- (void)clearDiskOnCompletion:(nullable SDWebImageNoParamsBlock)completion;

/**
 * Async remove all expired cached image from disk. Non-blocking method - returns immediately.
 * 异步从磁盘中删除所有过期的缓存映像。 非阻塞方法-立即返回。
 * @param completionBlock A block that should be executed after cache expiration completes (optional)
 */
- (void)deleteOldFilesWithCompletionBlock:(nullable SDWebImageNoParamsBlock)completionBlock;

#pragma mark - Cache Info - 缓存信息

/**
 * Get the size used by the disk cache 
 * 获取磁盘缓存使用的大小
 */
- (NSUInteger)getSize;

/**
 * Get the number of images in the disk cache
 * 获取磁盘缓存中的映像数
 */
- (NSUInteger)getDiskCount;

/**
 * Asynchronously calculate the disk cache's size.
 * 异步计算磁盘缓存的大小。
 */
- (void)calculateSizeWithCompletionBlock:(nullable SDWebImageCalculateSizeBlock)completionBlock;

#pragma mark - Cache Paths - 缓存路径

/**
 *  Get the cache path for a certain key (needs the cache path root folder)
 *  根据key获取缓存路径(需要缓存路径根文件夹)
 * 
 *  @param key  the key (can be obtained from url using cacheKeyForURL)
 *  @param path the cache path root folder 缓存根文件夹的路径
 *
 *  @return the cache path
 */
- (nullable NSString *)cachePathForKey:(nullable NSString *)key inPath:(nonnull NSString *)path;

/**
 *  Get the default cache path for a certain key
 *  根据key获取默认的缓存路径
 *
 *  @param key the key (can be obtained from url using cacheKeyForURL)
 *
 *  @return the default cache path
 */
- (nullable NSString *)defaultCachePathForKey:(nullable NSString *)key;

3、SDWebImageDownloader
SDWebImageDownloader完成了对网络图片的异步下载工作,就是一个文件下载的工具类,网络请求是在继承于NSOperationSDWebImageDownloaderOperation类实现的。SDWebImageDownloader的主要任务是下载相关配置项的管理,包括下载队列的先后顺序、最大下载任务数量控制、下载队列中的任务创建、取消、暂停等任务管理,以及其他 HTTPS 和 HTTP Header的设置。

  • SDWebImageDownloaderOptions:
typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) {
    //默认模式
    SDWebImageDownloaderLowPriority = 1 << 0,
    //本模式在返回进度Block的同时,同时返回completedBlock,里面的UIImage就是当前下载时的图片,可以实现将图片一点点显示出来的功能
    SDWebImageDownloaderProgressiveDownload = 1 << 1,
    //默认情况下,http请求阻止使用NSURLCache对象。如果设置了这个标记,则NSURLCache会被http请求使用。
    SDWebImageDownloaderUseNSURLCache = 1 << 2,
    //如果image/imageData是从NSURLCache返回的,则completion这个回调会返回nil
    SDWebImageDownloaderIgnoreCachedResponse = 1 << 3,
    //如果app进入后台模式,是否继续下载,这个是通过在后台申请时间来完成这个操作。如果指定的时间范围内没有完成,则直接取消下载。
    SDWebImageDownloaderContinueInBackground = 1 << 4,
    //处理缓存在`NSHTTPCookieStore`对象里面的cookie,通过设置`NSMutableURLRequest.HTTPShouldHandleCookies = YES`来实现的。
    SDWebImageDownloaderHandleCookies = 1 << 5,
    //允许非信任的SSL证书请求。在测试的时候很有用,但是正式环境要小心使用。
    SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6,
    //默认情况下,图片加载的顺序是根据加入队列的顺序加载的。但是这个标记会把任务加入队列的最前面。
    SDWebImageDownloaderHighPriority = 1 << 7,
    //默认情况下,图片会按照它的原始大小来解码显示。这个属性会根据设备的内存限制调整图片的尺寸到合适的大小。如果`SDWebImageProgressiveDownload`标记被设置了,则这个flag不起作用。
    SDWebImageDownloaderScaleDownLargeImages = 1 << 8,
};

在使用的时候,当判断options是否是SDWebImageDownloaderIgnoreCachedResponse选项时,应该这样来判断:

self.option & SDWebImageDownloaderIgnoreCachedResponse

SDWebImageDownloaderExecutionOrder
 

typedef NS_ENUM(NSInteger, SDWebImageDownloaderExecutionOrder) {
    /**
     * Default value. All download operations will execute in queue style (first-in-first-out).
     * 默认值。 所有下载操作将以队列方式(先进先出)执行。
     */
    SDWebImageDownloaderFIFOExecutionOrder,

    /**
     * All download operations will execute in stack style (last-in-first-out).
     * 所有下载操作将以堆栈样式(后进先出)执行。
     */
    SDWebImageDownloaderLIFOExecutionOrder
};
  • SDWebImageDownloadToken
/**
 The download's URL. This should be readonly and you should not modify
 下载的URL。 只读属性
 */
@property (nonatomic, strong, nullable) NSURL *url;
/**
 The cancel token taken from `addHandlersForProgress:completed`. This should be readonly and you should not modify
取消令牌取自`addHandlersForProgress:completed`。 只读属性
 @note use `-[SDWebImageDownloadToken cancel]` to cancel the token
 */
@property (nonatomic, strong, nullable) id downloadOperationCancelToken;

SDWebImageDownloadToken为每一个下载任务的唯一身份标识SDWebImageDownloader和我们平时开发中的下载有一些不同,它弱化了下载过程,比较强调的是下载结果,不支持断点下载。

  • SDWebImageDownloader的属性
/**
 * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory.
 * 对下载并缓存的图像进行解压缩可以提高性能,但会占用大量内存。
 * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption.
 * 默认为是。 如果由于过多的内存消耗而导致崩溃,请将其设置为NO。
 */
@property (assign, nonatomic) BOOL shouldDecompressImages;

/**
 *  The maximum number of concurrent downloads
 *  并发下载的最大数量
 */
@property (assign, nonatomic) NSInteger maxConcurrentDownloads;

/**
 * Shows the current amount of downloads that still need to be downloaded
 * 显示当前仍需要下载的下载量
 */
@property (readonly, nonatomic) NSUInteger currentDownloadCount;

/**
 *  The timeout value (in seconds) for the download operation. Default: 15.0.
 *  下载操作的超时值(以秒为单位)。 默认值:15.0。
 */
@property (assign, nonatomic) NSTimeInterval downloadTimeout;

/**
 * The configuration in use by the internal NSURLSession.
 * 内部NSURLSession使用的配置。
 * Mutating this object directly has no effect.
 *直接更改此对象无效。 
 *
 * @see createNewSessionWithConfiguration:
 * 使用配置创建新会话:
 */
@property (readonly, nonatomic, nonnull) NSURLSessionConfiguration *sessionConfiguration;


/**
 * Changes download operations execution order. Default value is `SDWebImageDownloaderFIFOExecutionOrder`.
 * 更改下载操作执行顺序。 默认值为“ SDWebImageDownloaderFIFOExecutionOrder”。
 */
@property (assign, nonatomic) SDWebImageDownloaderExecutionOrder executionOrder;

 

4、SDWebImageManager根据文档中的说明,就是对图片下载的管理类

//对SDWebImageManager的一个简单应用
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadImageWithURL:imageURL
                      options:0
                     progress:nil
                    completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                        if (image) {
                            // 得到image,展示或者干点其他的事情
    
                        }
                    }];

SDWebImageManager最主要的三个属性在上面已经讲过了,还有几个其他的属性和方法:


@property (weak, nonatomic) id <SDWebImageManagerDelegate> delegate;
@property (strong, nonatomic, readonly) SDImageCache *imageCache;
@property (strong, nonatomic, readonly) SDWebImageDownloader *imageDownloader;


//------------上面已经讲过了---------------
/**
 * The cache filter is a block used each time SDWebImageManager need to convert an URL into a cache key. This can be used to remove dynamic part of an image URL.
 * 缓存过滤器是SDWebImageManager每次需要将URL转换为缓存键时使用的block。 这可用于删除图像URL的动态部分。
 * 
 * The following example sets a filter in the application delegate that will remove any query-string from the URL before to use it as a cache key:
 *下面的示例在应用程序委托中设置一个过滤器,该过滤器将在使用URL作为缓存键之前从URL中删除所有查询字符串:
 * @code

[[SDWebImageManager sharedManager] setCacheKeyFilter:^(NSURL *url) {
    url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path];
    return [url absoluteString];
}];

 * @endcode
 */
@property (nonatomic, copy) SDWebImageCacheKeyFilterBlock cacheKeyFilter;

/**
 * Returns global SDWebImageManager instance.
 *
 * @return SDWebImageManager shared instance
 */
+ (SDWebImageManager *)sharedManager;

/**
 * Allows to specify instance of cache and image downloader used with image manager.
 * 允许指定与图像管理器一起使用的缓存和图像下载器的对象
 * @return new instance of `SDWebImageManager` with specified cache and downloader.
 */
- (instancetype)initWithCache:(SDImageCache *)cache downloader:(SDWebImageDownloader *)downloader;

/**
 * Downloads the image at the given URL if not present in cache or return the cached version otherwise.
 * 如果图片不在内存中,则用给定的url下载图片,否则返回内存中的图片
 *
 * @param url            The URL to the image
 * @param options        A mask to specify options to use for this request
 * @param progressBlock  A block called while image is downloading
 * @param completedBlock A block called when operation has been completed.
 *
 *   This parameter is required. 以上的参数是必须的
 * 
 *   This block has no return value and takes the requested UIImage as first parameter. 没有返回值的block,返回请求得到的image作为第一个返回值
 *   In case of error the image parameter is nil and the second parameter may contain an NSError. 返回图片为nil的时候,第二个参数为error
 *
 *   The third parameter is an `SDImageCacheType` enum indicating if the image was retrieved from the local cache
 *   or from the memory cache or from the network.
 *   返回SDImageCacheType这个枚举值,说明图片是从服务端还是从缓存或者磁盘中获取的
 *   The last parameter is set to NO when the SDWebImageProgressiveDownload option is used and the image is 
 *   downloading. This block is thus called repeatedly with a partial image. When image is fully downloaded, the
 *   block is called a last time with the full image and the last parameter set to YES. 
 * 重复回调的一个block,显示下载进度,如果没有下载完成返回NO,下载完成后返回YES
 *
 * @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation
 */
- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url
                                         options:(SDWebImageOptions)options
                                        progress:(SDWebImageDownloaderProgressBlock)progressBlock
                                       completed:(SDWebImageCompletionWithFinishedBlock)completedBlock;

/**
 * Saves image to cache for given URL
 * 保存图片的url
 * @param image The image to cache
 * @param url   The URL to the image
 *
 */

- (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url;

/**
 * Cancel all current operations
 * 取消当前所有操作,所有下载任务、线程、资源全部置空
 */
- (void)cancelAll;

/**
 * Check one or more operations running
 * 检查一项或多项正在运行的操作
 */
- (BOOL)isRunning;

/**
 *  Check if image has already been cached
 *  检查图像是否已经被缓存
 *  @param url image url
 *
 *  @return if the image was already cached
 */
- (BOOL)cachedImageExistsForURL:(NSURL *)url;

/**
 *  Check if image has already been cached on disk only
 *  检查图像是否仅已缓存在磁盘上
 *  @param url image url
 *
 *  @return if the image was already cached (disk only)
 */
- (BOOL)diskImageExistsForURL:(NSURL *)url;

/**
 *  Async check if image has already been cached
 *  异步检查图像是否已经被缓存
 *  @param url              image url
 *  @param completionBlock  the block to be executed when the check is finished
 *  
 *  @note the completion block is always executed on the main queue
 */
- (void)cachedImageExistsForURL:(NSURL *)url
                     completion:(SDWebImageCheckCacheCompletionBlock)completionBlock;

/**
 *  Async check if image has already been cached on disk only
 *  异步检查图像是否被存在磁盘中
 *  @param url              image url
 *  @param completionBlock  the block to be executed when the check is finished
 *
 *  @note the completion block is always executed on the main queue
 */
- (void)diskImageExistsForURL:(NSURL *)url
                   completion:(SDWebImageCheckCacheCompletionBlock)completionBlock;


/**
 *Return the cache key for a given URL
 * 获取url在存储图片的key
 */
- (NSString *)cacheKeyForURL:(NSURL *)url;

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值