SDWebImage SD_setImage中返回的cacheType值意味着什么?

8hhllhi2  于 2022-10-04  发布在  Swift
关注(0)|答案(1)|浏览(115)

我已经使用UITablelViewCells中的sd_setImage()将缓存的图像添加到UIImageview,如下所示。

imageView.sd_setImage(with: url, placeholderImage: defaultImage) { image, error, cacheType, cacheURL in

}

我的问题是,当加载新的细胞时,图像有时会从服务器重新获取,而实际上它应该在缓存中,而我不知道为什么。在调试期间,我一直在记录cacheType,但它只打印为Int值,范围为0、1、2。

我在SdWebImage文档中找不到任何地方记录的这些值。在一个目标C.h文件中,它被定义为SDImageCacheType类型,如下所示,但我不清楚如何将数字转换为类型。

typedef NS_ENUM(NSInteger, SDImageCacheType) {
    /**
     * For query and contains op in response, means the image isn't available in the image cache
     * For op in request, this type is not available and take no effect.
     */
    SDImageCacheTypeNone,
    /**
     * For query and contains op in response, means the image was obtained from the disk cache.
     * For op in request, means process only disk cache.
     */
    SDImageCacheTypeDisk,
    /**
     * For query and contains op in response, means the image was obtained from the memory cache.
     * For op in request, means process only memory cache.
     */
    SDImageCacheTypeMemory,
    /**
     * For query and contains op in response, this type is not available and take no effect.
     * For op in request, means process both memory cache and disk cache.
     */
    SDImageCacheTypeAll
};

是只有我,还是其他人觉得SDWebImage文档非常令人困惑和难以理解?

qvsjd97n

qvsjd97n1#

下面使用Switch语句的输出将匹配的缓存枚举与它们的Int值进行匹配。希望这能为其他人节省几分钟时间。

/**
     * the image isn't available in the image cache
     */
    SDImageCacheTypeNone = 0
    /**
     * the image was obtained from the disk cache.
     */
    SDImageCacheTypeDisk = 1
    /**
     * the image was obtained from the memory cache.
     */
    SDImageCacheTypeMemory = 2
 */

相关问题