Skip to content

Commit 5cd7c0d

Browse files
author
Olivier Poitrey
committed
Fix condition logic issue in SDWebImage#326
1 parent bbad1bc commit 5cd7c0d

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

SDWebImage/SDWebImageManager.m

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,15 @@ - (NSString *)cacheKeyForURL:(NSURL *)url
9494
{
9595
if (operation.isCancelled) return;
9696

97-
if (image)
97+
if ((!image || options & SDWebImageRefreshCached) && (![self.delegate respondsToSelector:@selector(imageManager:shouldDownloadImageForURL:)] || [self.delegate imageManager:self shouldDownloadImageForURL:url]))
9898
{
99-
completedBlock(image, nil, cacheType, YES);
100-
if (!(options & SDWebImageRefreshCached)) {
101-
@synchronized(self.runningOperations)
102-
{
103-
[self.runningOperations removeObject:operation];
104-
}
99+
if (image && options & SDWebImageRefreshCached)
100+
{
101+
// If image was found in the cache bug SDWebImageRefreshCached is provided, notify about the cached image
102+
// AND try to re-download it in order to let a chance to NSURLCache to refresh it from server.
103+
completedBlock(image, nil, cacheType, YES);
105104
}
106-
}
107105

108-
if ((!image || options & SDWebImageRefreshCached) && (![self.delegate respondsToSelector:@selector(imageManager:shouldDownloadImageForURL:)] || [self.delegate imageManager:self shouldDownloadImageForURL:url]))
109-
{
110106
// download if no image or requested to refresh anyway, and download allowed by delegate
111107
SDWebImageDownloaderOptions downloaderOptions = 0;
112108
if (options & SDWebImageLowPriority) downloaderOptions |= SDWebImageDownloaderLowPriority;
@@ -172,7 +168,15 @@ - (NSString *)cacheKeyForURL:(NSURL *)url
172168
}];
173169
operation.cancelBlock = ^{[subOperation cancel];};
174170
}
175-
else if (!image)
171+
else if (image)
172+
{
173+
completedBlock(image, nil, cacheType, YES);
174+
@synchronized(self.runningOperations)
175+
{
176+
[self.runningOperations removeObject:operation];
177+
}
178+
}
179+
else
176180
{
177181
// Image not in cache and download disallowed by delegate
178182
completedBlock(nil, nil, SDImageCacheTypeNone, YES);

0 commit comments

Comments
 (0)