Created
October 23, 2012 16:20
-
-
Save pita5/3939836 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (CSMCacheResponse *)cachedResponseForRequestURL:(NSURL *)url | |
{ | |
__block CSMCacheResponse* cachedResponse = nil; | |
__weak CSMCache* weakSelf = self; | |
dispatch_sync(requestQueue, ^{ | |
// Keep the weak self until function returns | |
__strong CSMCache* strongSelf = weakSelf; | |
if (strongSelf.cacheDictionary && | |
url.csm_cacheKey && | |
(cachedResponse = strongSelf.cacheDictionary[url.csm_cacheKey]) && | |
[cachedResponse isKindOfClass:[CSMCacheResponse class]]) | |
{ | |
// Increment our cache hit for a URL in memory. | |
[strongSelf csm_cacheHitFromMemory:url]; | |
} | |
else | |
{ | |
if (fileManager && | |
url.csm_cachePath && | |
[fileManager fileExistsAtPath:url.csm_cachePath.absoluteString]) | |
{ | |
@try | |
{ | |
cachedResponse = [NSKeyedUnarchiver unarchiveObjectWithFile:url.csm_cachePath.absoluteString]; | |
} | |
@catch (NSException *exception) | |
{ | |
cachedResponse = nil; | |
} | |
@finally | |
{ | |
if (cachedResponse) | |
{ | |
// Increment our cache hit for a URL on disk. | |
[strongSelf csm_cacheHitFromDisk:url]; | |
} | |
} | |
} | |
} | |
}); | |
return cachedResponse; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment