Accessibility

TechNote

How to prevent caching of loaded variables

Issue


When loading data, SWF files,or images from an external data source, some browsers may save the loaded object in the browser cache. This results in subsequent calls retrieving the cached item instead of the most recent item from the original source.

This can affect any class that loads data, images or SWF files. For example, in ActionScript 2.0, this can affect the LoadVars class and the XML class, as well as image and SWF loading via the Loader component or the movieClipLoader class.

In ActionScript 3.0, this can affect the following classes: XML, Loader, URLLoader, URLVariables, XMLDocument; and components which utilize these classes, such as ScrollPane.

Solution


To ensure that your SWF file always loads the most recent information from the original source, you can "trick" the SWF into thinking each loading action is unique.This is done by generating a random variable at the end of the action using a query string and Math.random. This forces Adobe Flash Player to internally "refresh" the data every time you load the data from the external source.

The following examples generate a random query string to avoid caching the variables:

 loadVariables("mypage.asp?nocache=" + random(65000), 0, "POST"); myXML.load("path.xml" + "?" + Math.random() ); 

Additional Information


For more details about working with external data sources, see "Overview of Adobe Flash and database integration" (TechNote 14482). For information about preventing caching of SWF files, refer to "How to prevent caching of SWF files" (TechNote 14743).

AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support


Document Details

ID:tn_15951
Browser:Chrome
Internet Explorer
Netscape
Opera
Safari
Firefox
Database:DB2
Informix
MySQL
Oracle
SQL Server
Sybase
MS Access

Products Affected:

flash
flashplayer