我运行这段代码是因为我认为我遇到了缓存问题:
NSCachedURLResponse *response = [[NSURLCache sharedURLCache] cachedResponseForRequest:request];
if(response){
NSLog(@"Got Response");
}else{
NSLog(@"No Response");
}
我的问题是如何清除请求 URL 的缓存?
最佳答案
NSURLRequest 有一个cachePolicy 属性,它指定请求的缓存行为。
在发出如下例所示的请求时,设置以下缓存策略 NSURLRequestReloadIgnoringLocalCacheData 将从 URL 加载数据,而不是从缓存加载数据。
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
NSURLRequestReloadIgnoringLocalCacheData
Specifies that the data for the URL load should be loaded from the originating source. No existing cache data should be used to satisfy a URL load request.
关于ios - Objective-c 清除缓存 NSCachedURLResponse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29627824/