I'm developing an iPhone app, that uses ASIHTTPRequest library. I''m stuck with the cache and download data. When I first open the app, it makes a request and download and cache the JSON response of the server. If I make some changes in this JSON so the content is now different, the app is supposed to catch that there's new changes and my tableview should get uploaded. It doesn't, it downloads the stored cache. The code is:
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url2];
[[ASIDownloadCache sharedCache] setShouldRespectCacheControlHeaders:NO];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request setCachePolicy:ASIAskServerIfModifiedCachePolicy|ASIFallbackToCacheIfLoadFailsCachePolicy];
[request setSecondsToCache:60*60*24*30]; // Cache for 30 days
[request setDidFailSelector:@selector(requestFailed:)];
[request setDidFinishSelector:@selector(requestFinished:)];
[request setDelegate:self]; // A delegate must be specified
[request startAsynchronous];
I'm reading the ASIHTTPRequest tutorial and it says:
"ASIHTTPRequest can automatically store downloaded data in a cache for use later. This can be helpful in many situations:"
You want to download something only if it has changed since you last downloaded it.
ASIAskServerIfModifiedCachePolicy
This is the same as ASIAskServerIfModifiedWhenStaleCachePolicy, except that requests will always ask the server if updated data is available.
So I think I'm using the right cache policies, but my app doesn't do what I want. I'm wondering of what they mean when they say: ask the server if updated data is available??? How can I know if there are updated data? With the Last-modified header response? If so, my server is sending the Last-modified header correctly...
Thanks in advance!