美文网首页
NSURLCache

NSURLCache

作者: younger_times | 来源:发表于2017-11-28 16:36 被阅读91次

    NSURLCache

    • Framework
      • Foundation
    • SDKs
      • iOS 8.0+
      • macOS 10.10+
      • tvOS 9.0+
      • watchOS 2.0+

    It provides a composite in-memory and on-disk cache, and lets you manipulate the sizes of both the in-memory and on-disk portions. You can also control the path where cache data is stored persistently.
    提供内存和磁盘缓存,操纵和分配在内存和磁盘的存储大小,你也可以控制存储的路径

    在iOS中,当设备的磁盘空间不足时,在磁盘存储的数据将会被清理

    线程安全

    在iOS8+,macOS10.10+ NSURLCache是线程安全的。

    @property(class, strong) NSURLCache *sharedURLCache;

    返回NSURLCache实例

    - (instancetype)initWithMemoryCapacity:(NSUInteger)memoryCapacity diskCapacity:(NSUInteger)diskCapacity diskPath:(NSString *)path;

    初始化NSURLCache指定值,MemoryCapacitymemoryCapacity指定了缓存大小(bytes)diskPath指定磁盘位置

    - (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request;

    返回一个被缓存过的响应请求

    - (void)storeCachedResponse:(NSCachedURLResponse *)cachedResponse forRequest:(NSURLRequest *)request;

    存储缓存的URL响应的请求。

    - (void)getCachedResponseForDataTask:(NSURLSessionDataTask *)dataTask completionHandler:(void (^)(NSCachedURLResponse *cachedResponse))completionHandler;

    No overview available.

    - (void)storeCachedResponse:(NSCachedURLResponse *)cachedResponse forDataTask:(NSURLSessionDataTask *)dataTask;

    No overview available.

    - (void)removeCachedResponseForRequest:(NSURLRequest *)request;

    清除缓存

    - (void)removeCachedResponseForDataTask:(NSURLSessionDataTask *)dataTask;

    No overview available.

    - (void)removeCachedResponsesSinceDate:(NSDate *)date;

    No overview available. 从什么时间开始清除缓存

    - (void)removeAllCachedResponses;

    No overview available. 移除所有缓存请求

    @property(readonly) NSUInteger currentDiskUsage;

    当前存储在磁盘中的存储大小,bytes字段

    @property NSUInteger diskCapacity;

    磁盘存储容量

    @property(readonly) NSUInteger currentMemoryUsage;

    当前存储在内存中的存储大小,bytes字段

    @property NSUInteger memoryCapacity;

    内存中存储容量


    参考文

    NSURLCache

    相关文章

      网友评论

          本文标题:NSURLCache

          本文链接:https://www.haomeiwen.com/subject/agdebxtx.html