Skip to content

Commit

Permalink
Updated default cache policy and performance tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
MKSG-MugunthKumar committed Dec 6, 2011
1 parent 65c9fcd commit 26e3c9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions MKNetworkKit/MKNetworkKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#define MKNETWORKCACHE_DEFAULT_COST 10
#define MKNETWORKCACHE_DEFAULT_DIRECTORY @"MKNetworkKitCache"
#define kMKNetworkKitDefaultCacheDuration 60 // 1 minute
#define kMKNetworkKitDefaultImageHeadRequestDuration 3600*24*1 // 1 day (HEAD requests with eTag are sent only after expiry of this. Not that these are not RFC compliant, but needed for performance tuning)
#define kMKNetworkKitDefaultImageCacheDuration 3600*24*7 // 1 day
#endif

Expand Down
10 changes: 8 additions & 2 deletions MKNetworkKit/MKNetworkOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,12 @@ - (id)initWithURLString:(NSString *)aURLString
finalURL = [NSURL URLWithString:aURLString];
}

// if your server takes longer than 30 seconds to provide real data,
// you should hire a better server developer.
// on iOS (or any mobile device), 30 seconds is already considered high.

self.request = [NSMutableURLRequest requestWithURL:finalURL
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:30.0f];

[self.request setHTTPMethod:method];
Expand Down Expand Up @@ -813,7 +817,9 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespon

// For images let's assume a expiry date of 7 days if there is no eTag or Last Modified.
if(!eTag && !lastModified)
expiresOnDate = [[NSDate date] dateByAddingTimeInterval:kMKNetworkKitDefaultImageCacheDuration];
expiresOnDate = [[NSDate date] dateByAddingTimeInterval:kMKNetworkKitDefaultImageCacheDuration];
else
expiresOnDate = [[NSDate date] dateByAddingTimeInterval:kMKNetworkKitDefaultImageHeadRequestDuration];
}

for(NSString *substring in cacheControlEntities) {
Expand Down

0 comments on commit 26e3c9b

Please sign in to comment.