@@ -94,19 +94,15 @@ - (NSString *)cacheKeyForURL:(NSURL *)url
94
94
{
95
95
if (operation.isCancelled ) return ;
96
96
97
- if (image)
97
+ if ((! image || options & SDWebImageRefreshCached) && (![ self .delegate respondsToSelector: @selector ( imageManager:shouldDownloadImageForURL: )] || [ self .delegate imageManager: self shouldDownloadImageForURL: url]) )
98
98
{
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 );
105
104
}
106
- }
107
105
108
- if ((!image || options & SDWebImageRefreshCached) && (![self .delegate respondsToSelector: @selector (imageManager:shouldDownloadImageForURL: )] || [self .delegate imageManager: self shouldDownloadImageForURL: url]))
109
- {
110
106
// download if no image or requested to refresh anyway, and download allowed by delegate
111
107
SDWebImageDownloaderOptions downloaderOptions = 0 ;
112
108
if (options & SDWebImageLowPriority) downloaderOptions |= SDWebImageDownloaderLowPriority;
@@ -172,7 +168,15 @@ - (NSString *)cacheKeyForURL:(NSURL *)url
172
168
}];
173
169
operation.cancelBlock = ^{[subOperation cancel ];};
174
170
}
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
176
180
{
177
181
// Image not in cache and download disallowed by delegate
178
182
completedBlock (nil , nil , SDImageCacheTypeNone, YES );
0 commit comments