0
votes

I am using ASIDownloadCache to cache the download files, the code below is how I set the request and downloadcache. `request = [super initWithURL:url1]; [request setTimeOutSeconds:50];

ASIDownloadCache *cache = [[ASIDownloadCache alloc] init] ;
[cache setStoragePath:[path stringByAppendingPathComponent:@"resource"]];
[cache setShouldRespectCacheControlHeaders:NO];

self.myCache = cache;    
[cache release];
[request setDownloadCache:self.myCache];   
//[self setSecondsToCache:60*60*24*30];
[request setCachePolicy:ASIAskServerIfModifiedCachePolicy];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];

` My problem is that when the url's header has been modified, the ASIDownloadCache is still using the cached data. Why? Someone knows the answer?

The header of that url before changing is like the following:

HTTP/1.1 200 OK Server: Apache/2.2 Cache-Control: public Content-Type: text/html; charset=UTF-8 Date: Mon, 07 Nov 2011 08:26:15 GMT Expires: Mon, 07 Nov 2011 08:23:35 GMT Pragma: public Transfer-Encoding: chunked Etag: 1320654215 Connection: Keep-Alive Last-Modified: Mon, 07 Nov 2011 08:23:35 GMT

The header after modifying is like the following:

HTTP/1.1 200 OK Server: Apache/2.2 Cache-Control: public Content-Type: text/html; charset=UTF-8 Date: Mon, 07 Nov 2011 08:28:49 GMT Expires: Mon, 07 Nov 2011 08:28:32 GMT Pragma: public Transfer-Encoding: chunked Etag: 1320654512 Connection: Keep-Alive Last-Modified: Mon, 07 Nov 2011 08:28:32 GMT

Even the Last-Modified fields are not the same, it is still using the cached data.

2
Use charlesproxy or similar to capture the request that ASIHTTPRequest is sending, and the response from the server, and add that into your question.JosephH
The headers are listed, is there anything wrong with the header?Terry
They look okay; I think you'll need to step through the code and see why it's deciding to use the cached data. breakpoint within readResponseHeaders and step through canUseCachedDataForRequestJosephH
I think I find the problem, when I get the header, the request hasn't completed. Even though the headers are different, it will also check whether the request has completed. So I think I should write my own caching. Thanks @JosephH.Terry

2 Answers

0
votes

I think I fond the problem. When I get the header, the request hasn't completed. Even though the headers are different, it will also check whether the request has completed. So I think I should write my own caching.

0
votes

The response is in the question :

[cache setShouldRespectCacheControlHeaders:NO];

You should use

[cache setShouldRespectCacheControlHeaders:YES];

For the cache to respect the headers information.

Hope it'll help.