NSURLRequest的缓存策略

刚刚看到了一个小知识点,拿出来与大家分享一下,也是做个笔记。

NSURLRequest有缓存策略,是这条属性:

/*! 
    @method cachePolicy
    @abstract Returns the cache policy of the receiver. 
    @result The cache policy of the receiver. 
*/
@property (readonly) NSURLRequestCachePolicy cachePolicy;
NSURLRequestCachePolicy 是一个枚举
typedef NS_ENUM(NSUInteger, NSURLRequestCachePolicy)
{
    NSURLRequestUseProtocolCachePolicy = 0,

    NSURLRequestReloadIgnoringLocalCacheData = 1,
    NSURLRequestReloadIgnoringLocalAndRemoteCacheData = 4, // Unimplemented
    NSURLRequestReloadIgnoringCacheData = NSURLRequestReloadIgnoringLocalCacheData,

    NSURLRequestReturnCacheDataElseLoad = 2,
    NSURLRequestReturnCacheDataDontLoad = 3,

    NSURLRequestReloadRevalidatingCacheData = 5, // Unimplemented
};

有这么几个值,分别是这些意思:

默认缓存策略:NSURLRequestUseProtocolCachePolicy

忽视本地缓存,只加载网络数据:NSURLRequestReloadIgnoringLocalCacheData

先加载本地缓存,没有的情况下网络请求数据:NSURLRequestReturnCacheDataElseLoad

不加载本地缓存,直接请求:NSURLRequestReturnCacheDataDontLoad

 

posted @ 2016-02-16 14:29  FrankieZ  阅读(728)  评论(0编辑  收藏  举报