当我测试时NSURLCache
,我得到“301PermMove”,这是我的代码
-(void)touchesBegan:(NSSet<UITouch *> *)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]);
}];
}
第一次触摸:缓存数据为 nil ,第二次触摸:缓存数据为 301PermMove 。为什么?我不知道。