New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config AFImageDownloader NSURLCache and ask AFImageRequestCache implementer if an image should be cached #4010

merged 9 commits into from Dec 15, 2017

Ask <AFImageRequestCache> implementor if an image should be cached. I…

…mplementors may prevent caching.
  • Loading branch information...
wjehenddher committed Jul 28, 2017
commit 51a80847ed9e55d067436cef1f032b2d58bc0bc7
@@ -72,6 +72,17 @@ NS_ASSUME_NONNULL_BEGIN
@protocol AFImageRequestCache <AFImageCache>
Asks if the image should be cached using an identifier created from the request and additional identifier.
@param image The image to be cached.
@param request The unique URL request identifing the image asset.
@param identifier The additional identifier to apply to the URL request to identify the image.
@return A BOOL indicating whether or not the image should be added to the cache. YES will cache, NO will prevent caching.
- (BOOL)shouldCacheImage:(UIImage *)image forRequest:(NSURLRequest *)request withAdditionalIdentifier:(nullable NSString *)identifier;
Adds the image to the cache using an identifier created from the request and additional identifier.
@@ -196,6 +196,10 @@ - (NSString *)imageCacheKeyFromURLRequest:(NSURLRequest *)request withAdditional
return key;
- (BOOL)shouldCacheImage:(UIImage *)image forRequest:(NSURLRequest *)request withAdditionalIdentifier:(nullable NSString *)identifier {
return YES;
@@ -266,7 +266,9 @@ - (nullable AFImageDownloadReceipt *)downloadImageForURLRequest:(NSURLRequest *)
} else {
[strongSelf.imageCache addImage:responseObject forRequest:request withAdditionalIdentifier:nil];
if ([strongSelf.imageCache shouldCacheImage:responseObject forRequest:request withAdditionalIdentifier:nil]) {
[strongSelf.imageCache addImage:responseObject forRequest:request withAdditionalIdentifier:nil];
for (AFImageDownloaderResponseHandler *handler in mergedTask.responseHandlers) {
if (handler.successBlock) {
ProTip! Use n and p to navigate between commits in a pull request.