先看代码:
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:(NSURLRequestCAchePolicy) timeoutInterval:(NSTiemInterval) ]
这里第一个参数没啥好说的具体说说第二个参数 NSURLRequestCAchePolicy
NSURLRequestUseProtocolCachePolicy = 0,
NSURLRequestReloadIgnoringLocalCacheData = 1,
NSURLRequestReloadIgnoringLocalAndRemoteCacheData = 4, // Unimplemented
NSURLRequestReloadIgnoringCacheData = NSURLRequestReloadIgnoringLocalCacheData,
NSURLRequestReturnCacheDataElseLoad = 2,
NSURLRequestReturnCacheDataDontLoad = 3,
NSURLRequestReloadRevalidatingCacheData = 5,
我们会看到5个枚举类型下面一一来解释下
首先看看xcode的英文解释
@discussion The NSURLRequestCachePolicy enum defines constants that
can be used to specify the type of interactions that take place with
the caching system when the URL loading system processes a request.
Specifically, these constants cover interactions that have to do
with whether already-existing cache data is returned to satisfy a
URL load request.
中文翻译:
@constant NSURLRequestUseProtocolCachePolicy Specifies that the
caching logic defined in the protocol implementation, if any, is
used for a particular URL load request. This is the default policy
for URL load requests.
中文翻译:基础策略
@constant NSURLRequestReloadIgnoringLocalCacheData Specifies that the
data for the URL load should be loaded from the origin source. No
existing local cache data, regardless of its freshness or validity,
should be used to satisfy a URL load request.
中文翻译:忽略本地缓存
@constant NSURLRequestReloadIgnoringLocalAndRemoteCacheData Specifies that
not only should the local cache data be ignored, but that proxies and
other intermediates should be instructed to disregard their caches
so far as the protocol allows. Unimplemented.
中文翻译:无视任何缓存策略,无论是本地的还是远程的,总是从原地址重新下载
@constant NSURLRequestReloadIgnoringCacheData Older name for
NSURLRequestReloadIgnoringLocalCacheData.
中文翻译:
NSURLRequestReloadIgnoringCacheData 是 NSURLRequestReloadIgnoringLocalCacheData 的旧名,这两个是一样的
@constant NSURLRequestReturnCacheDataElseLoad Specifies that the
existing cache data should be used to satisfy a URL load request,
regardless of its age or expiration date. However, if there is no
existing data in the cache corresponding to a URL load request,
the URL is loaded from the origin source.
中文翻译:首先使用缓存,如果没有本地缓存,才从原地址下载
@constant NSURLRequestReturnCacheDataDontLoad Specifies that the
existing cache data should be used to satisfy a URL load request,
regardless of its age or expiration date. However, if there is no
existing data in the cache corresponding to a URL load request, no
attempt is made to load the URL from the origin source, and the
load is considered to have failed. This constant specifies a
behavior that is similar to an "offline" mode.
中文翻译:使用本地缓存,从不下载,如果本地没有缓存,则请求失败,此策略多用于离线操作
@constant NSURLRequestReloadRevalidatingCacheData Specifies that
the existing cache data may be used provided the origin source
confirms its validity, otherwise the URL is loaded from the
origin source. Unimplemented.
中文翻译:如果本地缓存是有效的则不下载,其他任何情况都从原地址重新下载
第三个参数就是设置延迟时间,也就是你等他响应的时间。