Permalink
Browse files

Fix condition logic issue in #326

  • Loading branch information...
1 parent bbad1bc commit 5cd7c0db46381d18e812eaa93314712fdb2595be @rs committed Mar 12, 2013
Showing with 15 additions and 11 deletions.
  1. +15 −11 SDWebImage/SDWebImageManager.m
@@ -94,19 +94,15 @@ - (NSString *)cacheKeyForURL:(NSURL *)url
{
if (operation.isCancelled) return;
- if (image)
+ if ((!image || options & SDWebImageRefreshCached) && (![self.delegate respondsToSelector:@selector(imageManager:shouldDownloadImageForURL:)] || [self.delegate imageManager:self shouldDownloadImageForURL:url]))
{
- completedBlock(image, nil, cacheType, YES);
- if (!(options & SDWebImageRefreshCached)) {
- @synchronized(self.runningOperations)
- {
- [self.runningOperations removeObject:operation];
- }
+ if (image && options & SDWebImageRefreshCached)
+ {
+ // If image was found in the cache bug SDWebImageRefreshCached is provided, notify about the cached image
+ // AND try to re-download it in order to let a chance to NSURLCache to refresh it from server.
+ completedBlock(image, nil, cacheType, YES);
}
- }
- if ((!image || options & SDWebImageRefreshCached) && (![self.delegate respondsToSelector:@selector(imageManager:shouldDownloadImageForURL:)] || [self.delegate imageManager:self shouldDownloadImageForURL:url]))
- {
// download if no image or requested to refresh anyway, and download allowed by delegate
SDWebImageDownloaderOptions downloaderOptions = 0;
if (options & SDWebImageLowPriority) downloaderOptions |= SDWebImageDownloaderLowPriority;
@@ -172,7 +168,15 @@ - (NSString *)cacheKeyForURL:(NSURL *)url
}];
operation.cancelBlock = ^{[subOperation cancel];};
}
- else if (!image)
+ else if (image)
+ {
+ completedBlock(image, nil, cacheType, YES);
+ @synchronized(self.runningOperations)
+ {
+ [self.runningOperations removeObject:operation];
+ }
+ }
+ else
{
// Image not in cache and download disallowed by delegate
completedBlock(nil, nil, SDImageCacheTypeNone, YES);

0 comments on commit 5cd7c0d

Please sign in to comment.