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