Updated `storeImageDataToDisk:forKey:` asserting when called from other queue th…
…an ioQueue. Updated the header comments
Showing
2 changed files
with
10 additions
and
5 deletions
@@ -124,10 +124,12 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot | @@ -124,10 +124,12 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot | ||
124 | - (void)storeImage:(nullable UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(nullable NSData *)imageData forKey:(nullable NSString *)key toDisk:(BOOL)toDisk; | 124 | - (void)storeImage:(nullable UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(nullable NSData *)imageData forKey:(nullable NSString *)key toDisk:(BOOL)toDisk; |
125 | 125 | ||
126 | /** | 126 | /** |
127 | - * Store image NSData into disk cache at the given key. | 127 | + * Synchronously store image NSData into disk cache at the given key. |
128 | * | 128 | * |
129 | - * @param imageData The image data to store | ||
130 | - * @param key The unique image cache key, usually it's image absolute URL | 129 | + * @warning This method is synchronous, make sure to call it from the ioQueue |
130 | + * | ||
131 | + * @param imageData The image data to store | ||
132 | + * @param key The unique image cache key, usually it's image absolute URL | ||
131 | */ | 133 | */ |
132 | - (void)storeImageDataToDisk:(nullable NSData *)imageData forKey:(nullable NSString *)key; | 134 | - (void)storeImageDataToDisk:(nullable NSData *)imageData forKey:(nullable NSString *)key; |
133 | 135 |
@@ -209,11 +209,14 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | @@ -209,11 +209,14 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { | ||
209 | } | 209 | } |
210 | 210 | ||
211 | - (void)storeImageDataToDisk:(nullable NSData *)imageData forKey:(nullable NSString *)key { | 211 | - (void)storeImageDataToDisk:(nullable NSData *)imageData forKey:(nullable NSString *)key { |
212 | - | ||
213 | - if (!imageData) { | 212 | + if (!imageData || !key) { |
214 | return; | 213 | return; |
215 | } | 214 | } |
216 | 215 | ||
216 | + const char *currentQueueLabel = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL); | ||
217 | + const char *ioQueueLabel = dispatch_queue_get_label(self.ioQueue); | ||
218 | + NSAssert(strcmp(currentQueueLabel, ioQueueLabel) == 0, @"This method should be called from the ioQueue"); | ||
219 | + | ||
217 | if (![_fileManager fileExistsAtPath:_diskCachePath]) { | 220 | if (![_fileManager fileExistsAtPath:_diskCachePath]) { |
218 | [_fileManager createDirectoryAtPath:_diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL]; | 221 | [_fileManager createDirectoryAtPath:_diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL]; |
219 | } | 222 | } |
-
Please register or login to post a comment