Add one sync API for SDImageCache to directly get the image data from disk instead of image instance
This commit is contained in:
parent
39a28791fd
commit
5e52585944
|
@ -178,6 +178,14 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
*/
|
*/
|
||||||
- (BOOL)diskImageDataExistsWithKey:(nullable NSString *)key;
|
- (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.
|
||||||
|
*/
|
||||||
|
- (nullable NSData *)diskImageDataForKey:(nullable NSString *)key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Operation that queries the cache asynchronously and call the completion when done.
|
* Operation that queries the cache asynchronously and call the completion when done.
|
||||||
*
|
*
|
||||||
|
@ -203,6 +211,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
* Query the memory cache synchronously.
|
* Query the memory cache synchronously.
|
||||||
*
|
*
|
||||||
* @param key The unique key used to store the image
|
* @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;
|
- (nullable UIImage *)imageFromMemoryCacheForKey:(nullable NSString *)key;
|
||||||
|
|
||||||
|
@ -210,6 +219,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
* Query the disk cache synchronously.
|
* Query the disk cache synchronously.
|
||||||
*
|
*
|
||||||
* @param key The unique key used to store the image
|
* @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;
|
- (nullable UIImage *)imageFromDiskCacheForKey:(nullable NSString *)key;
|
||||||
|
|
||||||
|
@ -217,6 +227,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
|
||||||
* Query the cache (memory and or disk) synchronously after checking the memory cache.
|
* Query the cache (memory and or disk) synchronously after checking the memory cache.
|
||||||
*
|
*
|
||||||
* @param key The unique key used to store the image
|
* @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;
|
- (nullable UIImage *)imageFromCacheForKey:(nullable NSString *)key;
|
||||||
|
|
||||||
|
|
|
@ -399,6 +399,18 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
return exists;
|
return exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (nullable NSData *)diskImageDataForKey:(nullable NSString *)key {
|
||||||
|
if (!key) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
__block NSData *imageData = nil;
|
||||||
|
dispatch_sync(self.ioQueue, ^{
|
||||||
|
imageData = [self diskImageDataBySearchingAllPathsForKey:key];
|
||||||
|
});
|
||||||
|
|
||||||
|
return imageData;
|
||||||
|
}
|
||||||
|
|
||||||
- (nullable UIImage *)imageFromMemoryCacheForKey:(nullable NSString *)key {
|
- (nullable UIImage *)imageFromMemoryCacheForKey:(nullable NSString *)key {
|
||||||
return [self.memCache objectForKey:key];
|
return [self.memCache objectForKey:key];
|
||||||
}
|
}
|
||||||
|
@ -459,7 +471,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (nullable UIImage *)diskImageForKey:(nullable NSString *)key {
|
- (nullable UIImage *)diskImageForKey:(nullable NSString *)key {
|
||||||
NSData *data = [self diskImageDataBySearchingAllPathsForKey:key];
|
NSData *data = [self diskImageDataForKey:key];
|
||||||
return [self diskImageForKey:key data:data];
|
return [self diskImageForKey:key data:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue