Jed

How do I stop caching of the xml files?

Recommended Posts

I have a site where an xml is created per user and the contents change based on filters applied by the user.

THe issue is that the xml file is cached when the user firsts visits and I can't force refresh.

The problem really lies in Flash and usually I would call the xml file with a dyanamic variable name like this.

xmlfile.xml?stopcaching=<%=NOW()%>

But I am calling it using fusioncharts great little javascript

chart1.setDataURL("xmlfile.xml");

 

chart1.setDataURL("xmlfile.xml?stopcaching=<%=NOW()%>");

Doesn't work.

Anyone else have this issue?

Share this post


Link to post
Share on other sites

You can use the following JavaScript code to stop caching of XML data:

chart1.setDataURL(escape("xmlfile.xml?currTime=" + getTimeForURL()));
/**
  * getTimeForURL method returns the current time 
  * in a URL friendly format, so that it can be appended to
  * dataURL for effective non-caching.
 */
 function getTimeForURL(){
  var dt = new Date();
  var strOutput = "";
  strOutput = dt.getHours() + "_" + dt.getMinutes() + "_" + dt.getSeconds() + "_" + dt.getMilliseconds();
  return strOutput;
 }

Share this post


Link to post
Share on other sites
Pallav (1/2/2007)
You can use the following JavaScript code to stop caching of XML data:

chart1.setDataURL(escape("xmlfile.xml?currTime=" + getTimeForURL()));
/**
  * getTimeForURL method returns the current time 
  * in a URL friendly format, so that it can be appended to
  * dataURL for effective non-caching.
 */
 function getTimeForURL(){
  var dt = new Date();
  var strOutput = "";
  strOutput = dt.getHours() + "_" + dt.getMinutes() + "_" + dt.getSeconds() + "_" + dt.getMilliseconds();
  return strOutput;
 }

 

was just looking for this myself, works a treat thanks

Share this post


Link to post
Share on other sites

I guess I'm doing something similar, in that I'm auto-refreshing a very basic 2D graph which refers to an XML file on the same webserver.  This XML file is updated every 10 seconds but even when the webpage is refreshed (with the standard HTML NO-CACHE tags etc), the data doesn't change to reflect the new settings/data in the XML file.

I'm using the embedded flash method on the webpage itself - so how can I insert code similar to the above to ensure it doesn't cache the XML data each time it auto-refeshes?

thanks!

Share this post


Link to post
Share on other sites

I think I worked it out by accident by trying stuff from the forums :)

<param name="FlashVars" value="&dataURL=Data/OVDPCdata.xml?stopcaching=<%=NOW()%>">

But I'm presuming this isn't the correct method?

Share this post


Link to post
Share on other sites

Dear Pallav

In the earlierpost you said

"You can try putting the noCache flag at the end of both SWF and XML"

How do I add nocache flag to the swf file?

Im a newbie and im sorry for my ignorance.

Regards

Share this post


Link to post
Share on other sites

Most of people suggest adding a random parameter to the URL and nothing can be better than adding time as paramenter in URL. However I have no luck in getting flash to supress cache and request fresh data.

Any one here have similar problem ?

Share this post


Link to post
Share on other sites

I am facing a similar problem where in the JRE is caching my xml file. Is there a way to not use the random number approach and insert some type of the cache control header in the xml file itself so that i still have a parsable xml file and such that any changes to the xml files are reflected without disabling the cache?

Share this post


Link to post
Share on other sites

Hi,

 

 

 

Even if you insert a non-caching string as XML header, that doesn't force the browser at client side to reload new XML. As such, you need to "fool" the browser.

Share this post


Link to post
Share on other sites

Can anybody please help me out with this issue of caching? If its normal URL call i can append a random number. But i am integrating fusion charts with openlaszlo and i am using the following code to create a chart. 

<fusioncharts id="fc1" autoload="false"
strSWFName="Charts/Pie3D.swf"
intChartWidth="350"
intChartHeight="150" intChartStartX="0"
intChartStartY="5" timetoload="1000"/>
</view>

I am providing the data to it via a Dataset. how can i prevent caching in this scenario. Help is appreciated.Thanks is advance..

Edited by Guest

Share this post


Link to post
Share on other sites

Hi,

I'm experiencing the same issue with caching XMLs. I've tried the above menitioned solutions(adding noCache to both the .swf and .xml URLs) but they don't work for me. The only difference I find is that I don't call an actual xml file as such, instead i call a .aspx file that automattically generates XML output. Se below for the code I use.

<script language="JavaScript" src="../js/FusionCharts.js"></script>
<div id="chartdiv" align="center">The chart will appear within this DIV. This text will be replaced by the chart.</div>
<script type="text/javascript">
var myChart = new FusionCharts("FusionChartsFree/Charts/FCF_Line.swf?noCache=1", "myChartId", "400", "300");
myChart.setDataURL("XMLData/myStepsLineGraphXML.aspx?noCache=1");
myChart.render("chartdiv");
</script>

I have also enabled HTML no cache using

<meta http-equiv="Cache-Control" content="no-cache" />

, that didn't help either.

Any help would be appreciated.

Share this post


Link to post
Share on other sites

Hi,

The value passed in noCache is static. myChart.setDataURL("XMLData/myStepsLineGraphXML.aspx?noCache=1");

You would need to pass a dynamic value which would be unique and different from the previous values. Say date stamp.

Could you please try  this?

myChart.setDataURL(escape("XMLData/myStepsLineGraphXML.aspx?noCache="+new Date().toGMTString()));

Share this post


Link to post
Share on other sites

Thank you!

 

 

 

That helped, though I had to change the code since I'm using C#.

 

 

 

This is my first time using FusionCharts and I love it!

 

 

 

Thanks again!

Share this post


Link to post
Share on other sites
I have tried everything suggested in this post so far, using an html document I replaced the default .xml source line with the following:
 
myChart.setDataURL(escape("XMLData/myStepsLineGraphXML.aspx?noCache="+new Date().toGMTString()));
 
Which resulted in the following error message when I attempted to reload the page:
 
"The map will replace this text. If any users do not have Flash Player 8 (or above), they'll see this message."
 
I should probably point out that before I changed the code, the html document loaded fine, except for the fact that the xml was being cached when I did not want it to.
 
As I mentioned in my previous post on the matter, I am not particularly knowledgable on javascript but I suspect the reason the html no longer works is due to the replacement of the static noCache value with one generated using code.  I tried copying the javascript snippet from earlier in this thread into my FusionMaps.js file, which did not change the result.
 
Any assistance in the above will be most gratefully received.
 
-M
Edited by Guest

Share this post


Link to post
Share on other sites

Have you made sure that you've included the FusionCharts.js or FusionMaps.js file depending on whether you're using the chart/map.

Share this post


Link to post
Share on other sites

Edited:  Corrected the code as I had not replaced the XML source path correctly.

map.setDataURL(escape("globe.map.info.xml"+new Date().toGMTString()));

Only one script error now:

* 'chart1' not defined.

I can't find where chart1 is mentioned in the html file.  I'm using FusionMaps, not FusionCharts, so is there a section of the .js file I need to edit, perhaps?

Edit2:

The piece of javascript code I inserted into FusionMaps.js as per instructions earlier in this thread is as follows:

chart1.setDataURL(escape("xmlfile.xml?currTime=" + getTimeForURL()));

As I am using FM, not FC, there needs to be a modification to this code somewhere.  If someone would kindly suggest suitable replacement code, I would be most grateful.

Edited by Guest

Share this post


Link to post
Share on other sites

Hi,

Please use a proper QueryString. Please also note that there should be no : (colon) character in the URL. Hence, valueOf() can be used instead.

map.setDataURL(escape("globe.map.info.xml?noCache="+new Date().valueOf()));

Could you please send us the code that you are using? There must be some trace of "chart1"  somewhere which is being accessed by JavaScript.

Share this post


Link to post
Share on other sites

Ah, wonderful.

I realised I had pasted an incorrect line of code into the FusionMaps.js, which I deleted.

I then replaced the line of html with the one you posted.  The system now works perfectly.

Many thanks for your help and patience.

Share this post


Link to post
Share on other sites

hi,

 

 

 

facing the same problem!

 

 

 

can someone tell me in simple english the exact place i would need to make this change, is it fusioncharts.js ?

 

 

 

I have absolutely no idea of any technical jargon, would really appreciate help here.

 

Thanks.

Share this post


Link to post
Share on other sites
Guest Basundhara Ghosal
Hi All,

 

 

 

Ah, wonderful.

 

I realised I had pasted an incorrect line of code into the FusionMaps.js, which I deleted.

 

I then replaced the line of html with the one you posted. The system now works perfectly.

 

Many thanks for your help and patience.

 

 

 

Thanks for your appreciation.

 

 

 

We are happy to help you.

 

 

 

Happy FusionCharting. :)

 

 

 

 

 

 

I am going to begin testing the Fusion Charts DOM.

 

 

 

How do you prevent the caching issue with the DOM?

 

 

 

Thanks!

 

 

 

Could you please specify the issue a bit elaborately?

 

 

 

Awaiting your reply. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now