artifacts / AFCache

AFCache is an HTTP cache for iOS and OSX seeking towards full RFC2616 compliance
Apache License 2.0
361 stars 43 forks source link

cache-control not read #8

Closed dqueffeulouatw closed 10 years ago

dqueffeulouatw commented 13 years ago

It seems like sometimes the cache-control: max-age in the response is not read. Actually, I found maybe an explanation for that in the AFURLCache :

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

    [...]

        AFCacheableItem *item = [[AFCacheableItem alloc] initWithURL:oURL lastModified:lastModified expireDate:expireDate contentType:contentTypeHeader];
        // MUST BE DONE ??
        [item handleResponse:cachedResponse.response];
        //
        [[AFCache sharedInstance] importCacheableItem:item withData:cachedResponse.data];   
        [item release];
    }               
}

the handleResponse: is not called (I added myself), so all the stuff made on headers is not done, only those passed as parameters. Is it safe to call handleResponse: here ?

artifacts commented 10 years ago

Don't use AFURLCache anymore:

http://stackoverflow.com/questions/7166422/nsurlconnection-on-ios-doesnt-try-to-cache-objects-larger-than-50kb

Instead, register AFHTTPURLProtocol for http requests, so they'll be routed through AFCache:

[NSURLProtocol registerClass:[AFHTTPURLProtocol class]];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"]];
[self.webView loadRequest:request];