NSURLRequestCachePolicy 缓存策略

来源:互联网 发布:python splitlines 编辑:程序博客网 时间:2024/05/15 23:18
代码摘自:SDWebImage
- (void)start{    // In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:15];    self.connection = [[[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO] autorelease];    // Ensure we aren't blocked by UI manipulations (default runloop mode for NSURLConnection is NSEventTrackingRunLoopMode)    [connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];    [connection start];    [request release];    if (connection)    {        self.imageData = [NSMutableData data];        [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStartNotification object:nil];    }    else    {        if ([delegate respondsToSelector:@selector(imageDownloader:didFailWithError:)])        {            [delegate performSelector:@selector(imageDownloader:didFailWithError:) withObject:self withObject:nil];        }    }}
1
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:15];
1
1
1
1
1
 NSURLRequestCachePolicy 缓存策略
原文地址:点击打开链接
1> NSURLRequestUseProtocolCachePolicy = 0, 默认的缓存策略,如果缓存不存在,直接从服务端获取。如果缓存存在,会根据response中的Cache-Control字段判断下一步操作,如:Cache-Control字段为must-revalidata,则询问服务端该数据是否有更新,无更新的话直接返回给用户缓存数据,若已更新,则请求服务端.

2> NSURLRequestReloadIgnoringLocalCacheData = 1,忽略本地缓存数据,直接请求服务端.

3> NSURLRequestIgnoringLocalAndRemoteCacheData = 4,忽略本地缓存,代理服务器以及其他中介,直接请求源服务端.

4> NSURLRequestReloadIgnoringCacheData =NSURLRequestReloadIgnoringLocalCacheData

5> NSURLRequestReturnCacheDataElseLoad= 2, 有缓存就使用,不管其有效性(即忽略Cache-Control字段), 无则请求服务端.

6> NSURLRequ
0 0
原创粉丝点击