From 7a45de5d5eaa31fa04a2a4fb648d7c40ffde6354 Mon Sep 17 00:00:00 2001 From: Abe Heckenbach Date: Tue, 22 Apr 2014 12:27:25 +1000 Subject: [PATCH] Fixed bug in the handling of cache when reloadData == YES + operationSucceeded was being posted with cached data even if forceReload == YES which is not in accordance with the API comments on the enqueue method (Calling completion handler twice). --- MKNetworkKit/MKNetworkEngine.m | 2 +- MKNetworkKit/MKNetworkOperation.h | 2 +- MKNetworkKit/MKNetworkOperation.m | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/MKNetworkKit/MKNetworkEngine.m b/MKNetworkKit/MKNetworkEngine.m index a238f97..439909c 100644 --- a/MKNetworkKit/MKNetworkEngine.m +++ b/MKNetworkKit/MKNetworkEngine.m @@ -460,7 +460,7 @@ -(void) enqueueOperation:(MKNetworkOperation*) operation forceReload:(BOOL) forc if(cachedData) { dispatch_async(dispatch_get_main_queue(), ^{ // Jump back to the original thread here since setCachedData updates the main thread - [operation setCachedData:cachedData]; + [operation setCachedData:cachedData notifyObservers: !forceReload]; }); if(!forceReload) { diff --git a/MKNetworkKit/MKNetworkOperation.h b/MKNetworkKit/MKNetworkOperation.h index 427b78d..5bce8ca 100644 --- a/MKNetworkKit/MKNetworkOperation.h +++ b/MKNetworkKit/MKNetworkOperation.h @@ -680,7 +680,7 @@ typedef enum { // internal methods called by MKNetworkEngine only. // Don't touch -(BOOL) isCacheable; --(void) setCachedData:(NSData*) cachedData; +-(void) setCachedData:(NSData*) cachedData notifyObservers: (BOOL) notify; -(void) setCacheHandler:(MKNKResponseBlock) cacheHandler; -(void) updateHandlersFromOperation:(MKNetworkOperation*) operation; -(void) updateOperationBasedOnPreviousHeaders:(NSMutableDictionary*) headers; diff --git a/MKNetworkKit/MKNetworkOperation.m b/MKNetworkKit/MKNetworkOperation.m index 4932304..139e4d7 100644 --- a/MKNetworkKit/MKNetworkOperation.m +++ b/MKNetworkKit/MKNetworkOperation.m @@ -536,10 +536,11 @@ -(void) updateHandlersFromOperation:(MKNetworkOperation*) operation { [self.downloadStreams addObjectsFromArray:operation.downloadStreams]; } --(void) setCachedData:(NSData*) cachedData { +-(void) setCachedData:(NSData*) cachedData notifyObservers: (BOOL) notify { self.cachedResponse = cachedData; - [self operationSucceeded]; + if (notify) + [self operationSucceeded]; } -(void) updateOperationBasedOnPreviousHeaders:(NSMutableDictionary*) headers {