AFNetworking에는 이미지 용 메모리 캐시가 있습니다. 이미지가 100 개인 경우 적합 할 수 있습니다.
여기 NSURLCache에 대해서도 읽어야합니다 (http://nshipster.com/nsurlcache/).
NSURLCache를 사용하는 경우 캐싱에 대해 생각할 필요가 없습니다. 이미 캐싱 된 무언가를 다운로드하기 시작할 때 시스템에서 다운로드 한 파일 만 제공합니다.
업데이트 : 다운로드 된 데이터의 시간 만료는 서버가 응답으로 설정합니다. 하지만 편집하거나 NSURLConnectionDelegate 메서드에 의해 무시할 수 있습니다. 예 :
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)[cachedResponse response];
// Look up the cache policy used in our request
if([connection currentRequest].cachePolicy == NSURLRequestUseProtocolCachePolicy) {
NSDictionary *headers = [httpResponse allHeaderFields];
NSString *cacheControl = [headers valueForKey:@"Cache-Control"];
NSString *expires = [headers valueForKey:@"Expires"];
if((cacheControl == nil) && (expires == nil)) {
NSLog(@"server does not provide expiration information and we are using NSURLRequestUseProtocolCachePolicy");
return nil; // don't cache this
}
}
return cachedResponse;
}
출처
2014-02-16 23:16:46
Avt
AFNetworking Image 응답과 함께 NSURLCache를 사용할 수 있습니까? – user3300062
예. 너는 할 수 있었다. – Avt
좋습니다. 마지막 질문입니다. 답변을 수락 할 수 없을 때까지 어떻게 캐시를 저장할 시간을 설정할 수 있습니까? – user3300062