Permalink
Browse files

added priority downloading by ignoring the queue

  • Loading branch information...
1 parent 156ce18 commit 7ef898330721b5af41e9adff8ded8ca35e9c299e @artifacts committed Aug 5, 2013
@@ -16,14 +16,14 @@
<key>isShown</key>
<false/>
<key>orderHint</key>
- <integer>34</integer>
+ <integer>28</integer>
</dict>
<key>afcpkg.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
- <integer>22</integer>
+ <integer>18</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
View
@@ -72,6 +72,7 @@ enum {
kAFCacheRevalidateEntry = 1 << 13, // revalidate even when cache is switched to offline
kAFCacheNeverRevalidate = 1 << 14,
kAFCacheJustFetchHTTPHeader = 1 << 15, // just fetch the http header
+ kAFCacheIgnoreDownloadQueue = 1 << 16,
};
View
@@ -535,6 +535,7 @@ - (AFCacheableItem *)cachedObjectForURL: (NSURL *) url
BOOL revalidateCacheEntry = (options & kAFCacheRevalidateEntry) != 0;
BOOL neverRevalidate = (options & kAFCacheNeverRevalidate) != 0;
BOOL justFetchHTTPHeader = (options & kAFCacheJustFetchHTTPHeader) != 0;
+ BOOL shouldIgnoreQueue = (options & kAFCacheIgnoreDownloadQueue) != 0;
AFCacheableItem *item = nil;
BOOL didRewriteURL = NO; // the request URL might be rewritten by the cache internally if we're offline because the
@@ -631,7 +632,7 @@ - (AFCacheableItem *)cachedObjectForURL: (NSURL *) url
// Register item so that signalling works (even with fresh items
// from the cache).
[self registerItem:item];
- [self addItemToDownloadQueue:item];
+ [self handleDownloadItem:item ignoreQueue:shouldIgnoreQueue];
return item;
}
else
@@ -681,7 +682,7 @@ - (AFCacheableItem *)cachedObjectForURL: (NSURL *) url
// Check if item is fully loaded already
if (item.canMapData && nil == item.data && ![item hasValidContentLength])
{
- [self addItemToDownloadQueue:item];
+ [self handleDownloadItem:item ignoreQueue:shouldIgnoreQueue];
return item;
}
@@ -695,7 +696,7 @@ - (AFCacheableItem *)cachedObjectForURL: (NSURL *) url
{
//resume download
item.cacheStatus = kCacheStatusDownloading;
- [self addItemToDownloadQueue:item];
+ [self handleDownloadItem:item ignoreQueue:shouldIgnoreQueue];
}
#else
item.currentContentLength = item.info.contentLength;
@@ -736,7 +737,7 @@ - (AFCacheableItem *)cachedObjectForURL: (NSURL *) url
item.IMSRequest = theRequest;
ASSERT_NO_CONNECTION_WHEN_OFFLINE_FOR_URL(theRequest.URL);
- [self addItemToDownloadQueue:item];
+ [self handleDownloadItem:item ignoreQueue:shouldIgnoreQueue];
}
@@ -1425,6 +1426,15 @@ - (void)removeItemForURL:(NSURL*)url itemDelegate:(id)itemDelegate
[self fillPendingConnections];
}
+- (void)handleDownloadItem:(AFCacheableItem*)item ignoreQueue:(BOOL)ignoreQueue {
+ if (ignoreQueue == YES) {
+ if ((item != nil) && ![item isDownloading]) {
+ [self downloadItem:item];
+ }
+ } else {
+ [self addItemToDownloadQueue:item];
+ }
+}
// Add the item to the downloadQueue
- (void)addItemToDownloadQueue:(AFCacheableItem*)item

0 comments on commit 7ef8983

Please sign in to comment.