gpt4 book ai didi

ios - Objective-c 清除缓存 NSCachedURLResponse

转载 作者:行者123 更新时间:2023-11-29 02:07:33 25 4
gpt4 key购买 nike

我运行这段代码是因为我认为我遇到了缓存问题:

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.

https://developer.apple.com/library/prerelease/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/index.html#//apple_ref/c/tdef/NSURLRequestCachePolicy

关于ios - Objective-c 清除缓存 NSCachedURLResponse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29627824/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com