diff --git a/sonic-iOS/Sonic/SonicCache.m b/sonic-iOS/Sonic/SonicCache.m index fc17eda..73ac6f2 100644 --- a/sonic-iOS/Sonic/SonicCache.m +++ b/sonic-iOS/Sonic/SonicCache.m @@ -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 @@ -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 diff --git a/sonic-iOS/Sonic/SonicURLProtocol.m b/sonic-iOS/Sonic/SonicURLProtocol.m index 5bae568..4e6b1a7 100644 --- a/sonic-iOS/Sonic/SonicURLProtocol.m +++ b/sonic-iOS/Sonic/SonicURLProtocol.m @@ -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!");