PDA

View Full Version : preventing caching of loaded txt and xml files



littlered
April 24th, 2005, 10:51 AM
hi there,

I'm having trouble with my text and xml files seeming to be cached. They are altered by a php script called from flash, and this overwrites the text files correctly, but when they are reloaded into flash (eg. when the page is refreshed) the old data is still being used.

I was reading this (http://www.kirupa.com/web/xml/examples/simpleeditor.htm) article and was interested in this line:

input_xml.load(xml_file + "?uniq=" + new Date().getTime());

could someone please explain why this would work, and whether this would prevent the problem that I'm having. I'm presuming that this unique number is never used in any way, it just forces the new file to be loaded, but I'm just a bit unsure why.

thanks for any help!

MichaelxxOA
April 24th, 2005, 11:15 AM
it's quite simple, what it does is loads a text or xml file with the name of your choice, it appends the time onto the end of the file name, so you're file will look like this

xml_file.xml?uniq=81223; // or something similar

this file get's cached with Exactly that name, so if you change the file and try to load it again, it then load's xml_file.xml?unique81823, so this is not the same file as what is in your cache, so it loads it again off of the server. The computer ignores the variables at the end of the file only if there isn't a file that is name'd exactly like that.
Hope this helped.
-Michael

littlered
April 24th, 2005, 11:31 AM
that's brilliant - thanks!

(it's always good to understand things before using them!)