Permalink
Browse files

Serialize zip unpacking

  • Loading branch information...
1 parent b3a70f3 commit 553c03221a73a395f6361738cdfcf089ef3b04cf @nsc nsc committed Jan 24, 2011
Showing with 29 additions and 13 deletions.
  1. +7 −13 AFCache+Packaging.m
  2. +2 −0 AFCache.h
  3. +20 −0 AFCache.m
View
@@ -58,13 +58,10 @@ - (void)consumePackageArchive:(AFCacheableItem*)cacheableItem
cacheableItem, @"cacheableItem",
urlCacheStorePath, @"urlCacheStorePath",
nil];
-
- [NSThread detachNewThreadSelector:@selector(unzipThreadWithArguments:)
- toTarget:self
- withObject:arguments];
-
-
-
+
+ [packageArchiveQueue_ addOperation:[[[NSInvocationOperation alloc] initWithTarget:self
+ selector:@selector(unzipWithArguments:)
+ object:arguments] autorelease]];
}
enum ManifestKeys {
@@ -73,15 +70,14 @@ - (void)consumePackageArchive:(AFCacheableItem*)cacheableItem
ManifestKeyExpires = 2,
};
-- (void)unzipThreadWithArguments:(NSDictionary*)arguments
+- (void)unzipWithArguments:(NSDictionary*)arguments
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- [NSThread setThreadPriority:0.0];
#ifdef AFCACHE_LOGGING_ENABLED
NSLog(@"starting to unzip archive");
#endif
-
+
// get arguments from dictionary
NSString* pathToZip = [arguments objectForKey:@"pathToZip"];
AFCacheableItem* cacheableItem = [arguments objectForKey:@"cacheableItem"];
@@ -159,13 +155,11 @@ - (void)unzipThreadWithArguments:(NSDictionary*)arguments
waitUntilDone:YES];
[self performSelectorOnMainThread:@selector(archive) withObject:nil waitUntilDone:YES];
-
-
+
#ifdef AFCACHE_LOGGING_ENABLED
NSLog(@"finished unzipping archive");
#endif
-
[pool release];
}
View
@@ -84,6 +84,8 @@ enum {
BOOL downloadPermission_;
BOOL wantsToArchive_;
+
+ NSOperationQueue* packageArchiveQueue_;
}
@property BOOL cacheEnabled;
View
@@ -179,6 +179,10 @@ - (void)reinitialize {
}
requestCounter = 0;
_offline = NO;
+
+ [packageArchiveQueue_ release];
+ packageArchiveQueue_ = [[NSOperationQueue alloc] init];
+ [packageArchiveQueue_ setMaxConcurrentOperationCount:1];
}
// remove all expired cache entries
@@ -289,6 +293,22 @@ - (AFCacheableItem *)cachedObjectForURL: (NSURL *) url
username: nil password: nil];
}
+- (AFCacheableItem *)cachedObjectForURL: (NSURL *) url
+ delegate: (id) aDelegate
+ selector: (SEL) aSelector
+ options: (int) options
+ userData:(id)userData
+{
+
+ return [self cachedObjectForURL: url
+ delegate: aDelegate
+ selector: aSelector
+ didFailSelector: @selector(connectionDidFail:)
+ options: options
+ userData: userData
+ username: nil password: nil];
+}
+
- (AFCacheableItem *)cachedObjectForURL:(NSURL *)url delegate:(id) aDelegate selector:(SEL)aSelector didFailSelector:(SEL)didFailSelector options: (int) options {
return [self cachedObjectForURL:url delegate:aDelegate selector:aSelector didFailSelector:didFailSelector options:options userData:nil username:nil password:nil];

0 comments on commit 553c032

Please sign in to comment.