Removing code to try and be clever about cancelling image requests or not for a instances of the same image being requested
Adding HTTP pipelining to image requests
This commit is contained in:
parent
68dc7e866e
commit
4ac2f407d7
2 changed files with 13 additions and 21 deletions
|
|
@ -62,11 +62,9 @@ static inline CGSize kAFImageRequestRoundedCornerRadii(CGSize imageSize) {
|
|||
image = [UIImage imageByRoundingCornersOfImage:image corners:UIRectCornerAllCorners cornerRadii:kAFImageRequestRoundedCornerRadii(image.size)];
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^(void) {
|
||||
if (success) {
|
||||
success(image);
|
||||
}
|
||||
});
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
|
||||
[[AFImageCache sharedImageCache] cacheImage:image forRequest:request imageSize:imageSize options:options];
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@
|
|||
|
||||
#import "AFImageCache.h"
|
||||
|
||||
static NSOperationQueue *_operationQueue = nil;
|
||||
|
||||
static NSString * const kUIImageViewImageRequestObjectKey = @"imageRequestOperation";
|
||||
|
||||
@interface UIImageView (_AFNetworking)
|
||||
|
|
@ -48,11 +46,15 @@ static NSString * const kUIImageViewImageRequestObjectKey = @"imageRequestOperat
|
|||
objc_setAssociatedObject(self, kUIImageViewImageRequestObjectKey, imageRequestOperation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
+ (void)initialize {
|
||||
[super initialize];
|
||||
+ (NSOperationQueue *)sharedImageRequestOperationQueue {
|
||||
static NSOperationQueue *_imageRequestOperationQueue = nil;
|
||||
|
||||
_operationQueue = [[NSOperationQueue alloc] init];
|
||||
[_operationQueue setMaxConcurrentOperationCount:6];
|
||||
if (!_imageRequestOperationQueue) {
|
||||
_imageRequestOperationQueue = [[NSOperationQueue alloc] init];
|
||||
[_imageRequestOperationQueue setMaxConcurrentOperationCount:6];
|
||||
}
|
||||
|
||||
return _imageRequestOperationQueue;
|
||||
}
|
||||
|
||||
- (void)setImageWithURL:(NSURL *)url {
|
||||
|
|
@ -68,16 +70,9 @@ static NSString * const kUIImageViewImageRequestObjectKey = @"imageRequestOperat
|
|||
return;
|
||||
}
|
||||
|
||||
if (self.imageRequestOperation && ([self.imageRequestOperation isReady] || [self.imageRequestOperation isExecuting])) {
|
||||
if ([[[self.imageRequestOperation request] URL] isEqual:url]) {
|
||||
return;
|
||||
} else {
|
||||
[self.imageRequestOperation cancel];
|
||||
}
|
||||
}
|
||||
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageAllowed timeoutInterval:30.0];
|
||||
[request setHTTPShouldHandleCookies:NO];
|
||||
[request setHTTPShouldUsePipelining:YES];
|
||||
|
||||
UIImage *cachedImage = [[AFImageCache sharedImageCache] cachedImageForRequest:request imageSize:imageSize options:options];
|
||||
if (cachedImage) {
|
||||
|
|
@ -93,9 +88,8 @@ static NSString * const kUIImageViewImageRequestObjectKey = @"imageRequestOperat
|
|||
}
|
||||
}];
|
||||
|
||||
[_operationQueue addOperation:self.imageRequestOperation];
|
||||
[[[self class] sharedImageRequestOperationQueue] addOperation:self.imageRequestOperation];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue