URLLoader Caching Nightmares

January 11th, 2009 · 4 Comments

Why people are still using Internet Explorer 6 (or any version for that matter) is beyond me; but recently when developing a trending application for a company that only supports IE6 I ran into the age-old caching issue.  Normally, I would add a random number at the end of the URL string, however, this application has 30-40 different URLLoaders and that would just be annoying.  

For those who may not be aware, when loading dynamic XML data in Flash or Flex, say from a PHP page, if you are using the same link over and over again, IE6 decides that it only needs to check the link once.

It seems the easiest way to prevent caching in Internet Explorer is to set the Headers on the response of your data to “Pragma: no-cache” and “Cache-Control: no-store”.  Now this may be a little overkill, but for my problem, this was the only option.  You could try and allow a little more caching by using “Pragma: public” but this didn’t work in my case.

I’m using Java to serve XML data, so my code looks something like this (where op is a servlet request)

  1. op.getResponse().addHeader("Cache-Control", "no-store");
  2. op.getResponse().addHeader("Pragma", "no-cache");

But in PHP you could do this:

  1. Header("Cache-Control: no-store");
  2. Header("Pragma: no-cache");

Just remember, as always with the PHP Header() function, that you put this before anything is sent to the client – include any white space before your beginning <?php tag.

A great resource for more information (including a testing client) is located on the Less Rain Blog at http://www.blog.lessrain.com/flash-loading-and-browser-cache-test-suite/

Tags: ActionScript · Flash · Flex