ios - Objective-c 清除缓存 NSCachedURLResponse

标签 ios objective-c caching

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

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/

相关文章:

ios - 集成 Facebook 以从 iPhone 应用程序发布内容

iOS - 检查文件是否存在 Dropbox Sync API iOS SDK

iphone - 从其他常量构建常量变量列表

c# - 用户过滤结果的服务器端缓存策略

caching - 使用 nosql 数据存储时是否需要缓存层?

asp.net - 通过缓存、ThreadStatic 等降低 ASP.NET 中的初始化频率

ios - 仪器报告 libsystem_c 泄漏

ios - Swift:属性未在 super.init 调用时初始化

ios - 在 IOS 9 中合并音频文件时 AVAssetExportSessionStatusFailed

ios - UIView 和 ScrollView 之间的 UIView 过渡翻转