#99 new
Ruben

How does the ASIHTTPRequest know that there's new data from JSON response

Reported by Ruben | September 10th, 2011 @ 11:47 AM

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!

Comments and changes to this ticket

  • dave sailer

    dave sailer November 19th, 2011 @ 12:53 PM

    you might want to post the http headers on the request and response just to have a second set of eyes regarding the http caching parameters. It may not be a bug with ASI.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Easy to use CFNetwork wrapper for HTTP requests, Objective-C, Mac OS X and iPhone

People watching this ticket

Pages