开发者

XML cached in local testing

开发者 https://www.devze.com 2022-12-23 18:37 出处:网络
My question is about XML loading. I need to avoid xml caching. On a web server, the technique is adding arandom param to reload each time the XML file.

My question is about XML loading. I need to avoid xml caching.

On a web server, the technique is adding a random param to reload each time the XML file. But on local testing (in Flash CS4 IDE, CTRL + Enter), the following lines are not possible :

var my_date : Date;
path = "toto.xml?time="+my_date.getSeconds()+my_date.getMilliseconds();

Is there any trick to bypass this issue ? I've read on different forum about the "delete" method, we delete the xml object and then recreate one new.

In my case, I put : myXML = null; myXML = new开发者_JAVA百科 XML ( loadedData ); But it doesn't work at all.

I found something interesting but for Air 1.0 unfortunately with the cacheResponse. In AS3 I found :

var loader     : URLLoader  = new URLLoader();
var urlRequest : URLRequest = new URLRequest( xmlUrl );
var header     : URLRequestHeader = new URLRequestHeader ( "pragma", "no-cache" );
urlRequest.requestHeaders.push(header);

But it doesn't work.

I spent many hours on that problem, if anyone has a good solution... Thank you.


Recently I've started using a debug proxy that let's me disable caching altogether, but before I did that I used this little actionscript snippet to deal with this issue:

import flash.system.Capabilities;

var url:String = "foo.xml";
if (Capabilities.playerType == "StandAlone" || Capabilities.playerType == "External") {
    // running locally, cache busting not required
} else {
    // running in browser
    url += "?rnd=" + Math.random();
}


Major troll, but: Pragma isn't the best option for controlling cache. Take some time to study caching: http://www.mnot.net/cache_docs/#PRAGMA

And after all that, adding a random number to the end of the URL querystring is still a surefire way of get past all that monkeybusiness with caching.

0

精彩评论

暂无评论...
验证码 换一张
取 消