@@ -29,6 +29,7 @@ @interface FICImageCache () {
2929
3030 BOOL _delegateImplementsShouldProcessAllFormatsInFamilyForEntity;
3131 BOOL _delegateImplementsErrorDidOccurWithMessage;
32+ BOOL _delegateImplementsCancelImageLoadingForEntityWithFormatName;
3233}
3334
3435@end
@@ -47,6 +48,7 @@ - (void)setDelegate:(id<FICImageCacheDelegate>)delegate {
4748
4849 _delegateImplementsShouldProcessAllFormatsInFamilyForEntity = [_delegate respondsToSelector: @selector (imageCache:shouldProcessAllFormatsInFamily:forEntity: )];
4950 _delegateImplementsErrorDidOccurWithMessage = [_delegate respondsToSelector: @selector (imageCache:errorDidOccurWithMessage: )];
51+ _delegateImplementsCancelImageLoadingForEntityWithFormatName = [_delegate respondsToSelector: @selector (imageCache:cancelImageLoadingForEntity:withFormatName: )];
5052 }
5153}
5254
@@ -369,6 +371,31 @@ - (void)deleteImageForEntity:(id <FICEntity>)entity withFormatName:(NSString *)f
369371 [imageTable saveMetadata ];
370372}
371373
374+ - (void )cancelImageRetrievalForEntity : (id <FICEntity>)entity withFormatName : (NSString *)formatName {
375+ NSURL *sourceImageURL = [entity sourceImageURLWithFormatName: formatName];
376+ NSMutableDictionary *requestDictionary = [_requests objectForKey: sourceImageURL];
377+ if (requestDictionary) {
378+ NSString *entityUUID = [entity UUID ];
379+ NSMutableDictionary *entityRequestsDictionary = [requestDictionary objectForKey: entityUUID];
380+ if (entityRequestsDictionary) {
381+ NSMutableDictionary *completionBlocksDictionary = [entityRequestsDictionary objectForKey: FICImageCacheCompletionBlocksKey];
382+ [completionBlocksDictionary removeObjectForKey: formatName];
383+
384+ if ([completionBlocksDictionary count ] == 0 ) {
385+ [requestDictionary removeObjectForKey: entityUUID];
386+ }
387+
388+ if ([requestDictionary count ] == 0 ) {
389+ [_requests removeObjectForKey: sourceImageURL];
390+
391+ if (_delegateImplementsCancelImageLoadingForEntityWithFormatName) {
392+ [_delegate imageCache: self cancelImageLoadingForEntity: entity withFormatName: formatName];
393+ }
394+ }
395+ }
396+ }
397+ }
398+
372399- (void )reset {
373400 for (FICImageTable *imageTable in [_imageTables allValues ]) {
374401 [imageTable reset ];
0 commit comments