Skip to content

Commit

Permalink
Merge pull request #159 from sonic-ios-dev/dev
Browse files Browse the repository at this point in the history
Fix SonicURLProtocol error blocking request
  • Loading branch information
vasdeveloper authored Nov 9, 2017
2 parents 10fd89c + 53b73a5 commit 3eb0b20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
21 changes: 13 additions & 8 deletions sonic-iOS/Sonic/SonicCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,18 @@ - (void)setupDatabase

- (void)memoryWarningClearCache
{
[self clearAllCache];
[self clearMemoryCache];
}

- (void)clearMemoryCache
{
//we need clear or create memory cache in sonic queue
dispatchToSonicSessionQueue(^{
[self.lock lock];
[self.memoryCache removeAllObjects];
[self.recentlyUsedKey removeAllObjects];
[self.lock unlock];
});
}

- (void)clearAllCache
Expand All @@ -158,13 +169,7 @@ - (void)clearAllCache
[self setupDatabase];
});

//we need clear or create memory cache in sonic queue
dispatchToSonicSessionQueue(^{
[self.lock lock];
[self.memoryCache removeAllObjects];
[self.recentlyUsedKey removeAllObjects];
[self.lock unlock];
});
[self clearMemoryCache];
}

- (void)removeCacheBySessionID:(NSString *)sessionID
Expand Down
3 changes: 2 additions & 1 deletion sonic-iOS/Sonic/SonicURLProtocol.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ + (BOOL)canInitWithRequest:(NSURLRequest *)request
if (value.length != 0 && [value isEqualToString:SonicHeaderValueWebviewLoad]) {
NSString * delegateId = [request.allHTTPHeaderFields objectForKey:SonicHeaderKeyDelegateId];
if (delegateId.length != 0) {
NSString * sessionID = sonicSessionID(request.URL.absoluteString);
SonicSession *session = [[SonicEngine sharedEngine] sessionWithDelegateId:delegateId];
if (session) {
if (session && [sessionID isEqualToString:session.sessionID]) {
return YES;
}
NSLog(@"SonicURLProtocol.canInitWithRequest error:Cannot find sonic session!");
Expand Down

0 comments on commit 3eb0b20

Please sign in to comment.