当我测试时NSURLCache
,我得到了"301PermMove",这是我的代码
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event { NSURL *url = [NSURL URLWithString:@"https://www.github.com"]; NSURLRequest *urlRequest = [[NSURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10]; NSURLCache *shareCache = [NSURLCache sharedURLCache]; NSCachedURLResponse *resp = [shareCache cachedResponseForRequest:urlRequest]; NSLog(@"cache data:%@",[[NSString alloc]initWithData:resp.data encoding:NSUTF8StringEncoding]); [NSURLConnection sendAsynchronousRequest:urlRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) { NSLog(@"data:%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]); }]; }
第一次触摸:缓存数据为零,第二次触摸:缓存数据为301PermMove.为什么?我不知道.