ios url缓存策略——NSURLCache、 NSURLRequest
?
NSURLRequest
?
?
requestWithURL:cachePolicy:timeoutInterval:
?
1:NSURLRequestUseProtocolCachePolicy
This flag will use the underlying protocol’s caching mechanism if the protocol
supports it.
?
基礎(chǔ)策略
?
2:NSURLRequestReloadIgnoringLocalCacheData
This flag specifies that the local cached copy of the resource that is about to be
downloaded must be disregarded and the remote cache policy must be effective.
If there is a local copy of the resource, managed by the framework itself, it will be
ignored.
?
忽略本地緩存
?
?
3:NSURLRequestReturnCacheDataElseLoad
?
This flag specifies that the cached data must be used before attempting to load the
data from the original source. The cached data could be protocol-based cached or
locally cached. If there is no cached data, the data will be downloaded from the
original source.
?
首先使用緩存,如果沒(méi)有本地緩存,才從原地址下載
?
?
4:NSURLRequestReturnCacheDataDontLoad
This flag specifies that only the local cached data must be used. If the data has not
been cached, the request will fail. This is a great flag to use whenever your application
wants to perform operations in offline mode (such as the Offline Mode in
web browsers).
?
使用本地緩存,從不下載,如果本地沒(méi)有緩存,則請(qǐng)求失敗。此策略多用于離線操作
?
5:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
This flag disregards any type of caching involved in the process, local and remote,
and always attempts to download the data from the original source.
?
無(wú)視任何的緩存策略,無(wú)論是本地的還是遠(yuǎn)程的,總是從原地址重新下載
?
?
6:NSURLRequestReloadRevalidatingCacheData
?
This flag specifies that the original source of data must validate the local cache (if
any) before an attempt is made to download the data from the original source. If
there is a copy of the original source cached locally and the remote source specifies
that the cached data is valid, the data won’t be downloaded again. In any other
case, the data will be downloaded from the original source.
?
如果本地緩存是有效的則不下載。其他任何情況都從原地址重新下載
?
?
二:NSURLCache
?
NSURLCache *urlCache = [NSURLCache sharedURLCache];
?
?
In iOS, NSURLCache supports caching data only in memory and not
on disk.
?
(NSURLCache 僅支持內(nèi)存緩存,不支持硬盤(pán)緩存)
[cpp]?view plaincopyprint?
[cpp]?view plaincopyprint?
轉(zhuǎn)載于:https://www.cnblogs.com/zsw-1993/archive/2013/05/07/4880129.html
總結(jié)
以上是生活随笔為你收集整理的ios url缓存策略——NSURLCache、 NSURLRequest的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: [原创]修改oracle 数据库默认时间
- 下一篇: 演练GridView控件显示目录图片