When I was working on the polling application for my website which loads variables using a LoadVars call, I was facing this problem of the old file in the cache being always loaded and hence the data was not getting refreshed with the new values. After hours of experimenting I found out this cool way of stopping this caching problem. I am not sure if this is the best way to do it but it worked for me and yes every time the application was loaded I got the new values.
var dDate:Date = new Date();
dSec = dDate.getMilliseconds();
lvPollData.load(oPoll.textFileURL+"?"+dSec);
This is the code, which I used to load the poll data file. This code gets the milliseconds and queries it as a query string along with the load call and it’s random and different most of the time. Thought someone may find this useful.
Comments
yeah, that is known as a "cache-killer". I've seen people use it just by gereating a random number too.
While that sort of cache-killer is good for testing online, it breaks when tested in the IDE. Where you have data or movies being loaded in various locations, you can add in another bit of code to automate whether to kill the cache only if the movie is being tested online.
var cacheKill:Boolean = (_url.substr(0, 4) == "http");
var dSecs:String = cacheKill ? "?" + new Date.getMilliseconds() : "";
lvPollData.load(oPoll.textFileURL + dSec);
If you writing say a DAO class you can store cacheKill as a private member is it is completely transparent to anyone else wanting to use it.
That's right. With the Math.random function you get the same effect.
Here an example:
var randomNumber = int (Math.random () * 100000);
lvPollData.load(oPoll.textFileURL + "?" + randomNumber);