先看代碼:
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:(NSURLRequestCAchePolicy) timeoutInterval:(NSTiemInterval) ]
這里第一個參數(shù)沒啥好說的具體說說第二個參數(shù) 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.
中文翻譯:如果本地緩存是有效的則不下載,其他任何情況都從原地址重新下載
</code>
第三個參數(shù)就是設置延遲時間髓迎,也就是你等他響應的時間峦朗。