Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax and the Caching issue

 
Dinesh Sundrani
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Authors,

I have a Ajax code that calculates the time, the Web Service call took to fetch the data from the datatabse and display it on the GUI [i.e the Turnaround Time] on a respective div/iframe element.
But sometimes what I have usually observed is that the time is being cached and even though the total process took around 8.35345 seconds, It actually displays the old time [time it took for the previous request] which was for ex say 9.2 seconds. So is it that the browser is caching my variables or is that a overall Ajax Caching issue. Does someone else also have had the same issue? Does this Book cover Effective strategies of dealing with Caching and improving the cache-hit percentage. Is there a way to stop caching of my data in the browser or is there a way to refresh the stale data and keep it in sync with the new request?

Please suggest so that I could propose the changes to Dev-Team!!

Regards,
Dinesh Sundrani
*******************
SCJP1.5 [86%]
SCWCD [95%]
SCDJWS [98%]
*******************
[ July 26, 2007: Message edited by: Bear Bibeault ]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I only ever see this in IE and it's a fairly well known issue if you hit google on it. The solution I use is something like this..

Caveat is this code is Java. You'll need to adjust to your language of choice.


And then forward the request back to the client. The reason you need to do this in code is because IE is actually caching the HTML as a page that comes back so even if you added the meta tags to your HTML page, IE will never see them, as it pulls the cached page rather than the newly acquired page.

HTH
 
Alexei White
author
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a uniquely Internet Explorer issue. The solution we prefer is to use the cache-buster technique.. which is to append a unique string to the end of your XHR url for every request. Eg:

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alexei White:
This is a uniquely Internet Explorer issue. The solution we prefer is to use the cache-buster technique.. which is to append a unique string to the end of your XHR url for every request. Eg:



By solution, don't you mean hack? This is well documented out in google land as well for dealing with IE caching images that tend to change. You can put a random number on the end of the image src to force IE to recognize it's a new image. The same applies for other types of requests as well, obviously.

I only prefer my suggestion because it's using specifications (yes, even if they are just for IE) to make the browser play nice rather than a hack or trick. But it's purely preference in this case.
 
Dinesh Sundrani
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool, I googled my concern and I found the exact same solution as Gregg suggested me, Thanks a ton!!

Regards,
Dinesh Sundrani
*******************
[SCJP 1.5 - 86%]
[SCWCD - 95%]
[SCDJWS - 98%]
*******************
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic