Cache is a place to store something more or less temporarily. Web pages we’ve visited are stored in our browser’s cache directory on our hard disk. Likewise, ISPs and Web Servers cache web pages which speeds up access times for users, as the page is being read from the cache memory and not downloaded from the actual web site

It can become a problem when we are loading external content into flash and we update the files more frequently.
Say for example when we are loading an XML file in flash for content, some times we used to wonder why the changes we did in the XML file is not reflected in flash. It is because of Caching which is happening either in the server or in the browser. We have some server side solutions to avoid this problem when the data is dynamic but it won’t help when we update the files manually.

We can avoid such problems in flash itself by passing the randomized query string along with the filename. I’ve written the function which can be used for this purpose. Here is how you can use it.

//sample usage
#include "skipCache.as"
my_xml = new XML();
my_xml.onData = function(dta) {
        trace(dta);
};
my_xml.load("myfile.xml"+getSkipCacheString());

this getSkipCacheString() will return a blank string(“”) when the swf is running as a local file and returns a random string like “?CacheBuster=0.0308893630281091&timestamp=1073037565155” when the swf is loaded from a web server (i.e, Website)
You can download the actionscript file from here!

[UPDATE] included the ActionScript 3 version as well 🙂 It became lot more simpler with the regular expressions

[tabcontainer] [tabtext]ActionScript 3.0[/tabtext] [tabtext]ActionScript 1.0[/tabtext] [/tabcontainer] [tabcontent]
/*
 ************************************************************
   Developed by R.Arul Kumaran [[email protected]]
   for more code keep visiting [www.luracast.com/all/blog]
 ************************************************************
 */
 /*
Coming Soon....
*/

 */
/*
/*
**************************************************************
* Developed by R.Arul Kumaran [[email protected]]     *
* for more code keep visiting [www.shockwave-india.com/blog] *
**************************************************************
version 1.1 Last updated on 9, Jan 2004
*/
/*
| Useful when you don't want your server files to be cached by both server and browser
|
|   getSkipCacheString() - Return a blank string("") when the swf is running as a local file and
|                          returns a random string like "?CacheBuster=0.0308893630281091&timestamp=1073037565155"
|                          when the swf is from a web server
|
*/
_global.getSkipCacheString = function() {
        if (getSkipCacheString.isLocalPlayback) {
                return "";
        }
        dStr = "&timestamp="+new Date().getTime();
        return "?CacheBuster="+Math.random()+dStr;
};
getSkipCacheString.isLocalPlayback = _url.indexOf("file") == 0;
/*
//sample usage
#include "skipCache.as"
my_xml = new XML();
my_xml.onData = function(dta) {
trace(dta);
};
my_xml.load("myfile.xml"+getSkipCacheString());
*/
[/tabcontent]