網(wǎng)絡(luò)請求中緩存類NSURLCache
常用屬性和方法:
//獲取當(dāng)前應(yīng)用的緩存管理對象
+ (NSURLCache *)sharedURLCache;
//設(shè)置自定義的NSURLCache作為應(yīng)用緩存管理對象
+ (void)setSharedURLCache:(NSURLCache *)cache;
//初始化一個(gè)應(yīng)用緩存對象
/*
memoryCapacity 設(shè)置內(nèi)存緩存容量
diskCapacity 設(shè)置磁盤緩存容量
path 磁盤緩存路徑
內(nèi)容緩存會(huì)在應(yīng)用程序退出后 清空 磁盤緩存不會(huì)
*/
- (instancetype)initWithMemoryCapacity:(NSUInteger)memoryCapacity diskCapacity:(NSUInteger)diskCapacity diskPath:(nullable NSString *)path;
//獲取某一請求的緩存
- (nullable NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request;
//給請求設(shè)置指定的緩存
- (void)storeCachedResponse:(NSCachedURLResponse *)cachedResponse forRequest:(NSURLRequest *)request;
//移除某個(gè)請求的緩存
- (void)removeCachedResponseForRequest:(NSURLRequest *)request;
//移除所有緩存數(shù)據(jù)
- (void)removeAllCachedResponses;
//移除某個(gè)時(shí)間起的緩存設(shè)置
- (void)removeCachedResponsesSinceDate:(NSDate *)date NS_AVAILABLE(10_10, 8_0);
//內(nèi)存緩存容量大小
@property NSUInteger memoryCapacity;
//磁盤緩存容量大小
@property NSUInteger diskCapacity;
//當(dāng)前已用內(nèi)存容量
@property (readonly) NSUInteger currentMemoryUsage;
//當(dāng)前已用磁盤容量
@property (readonly) NSUInteger currentDiskUsage;