Control caching of your RIA applications

Posted on Apr 27, 2009

For all of us working with RIA applications (Flex/Flash) we know the hell of having to worry about a user cache.

There’s actually a chance that a user won’t see the latest version of your application, the chances are actually quite high for that to happen.

Well, I have my own two methods that I use to control this.

Method #1

The first way to control this is by the use of a parameter attached to the file name.

Lets say your file name is kenso.swf (original name I must say ). If you try embedding it into the HTML you will found out it is being cached. If you update the file on the server, you won’t see the changes.

The solution for this is simply add a parameter to the file like so: kenso.swf?buildDate=29Jan2009, this will cache as a file, if you change the buildDate param you will see that the file is being pulled again from the server

Method #2

This method is what I call overkill, but I did found myself using it a couple of times in the past.

I won’t get into code (unless you ask me to…), but the idea is this. There’s a service managing the builds of the application.

Each build of the application has an ID embedded inside the code like so:

<p>
  <!--CRLF-->
</p>

OK, so now we have the version label in the application. All we have to do is create a service, set the final version expected there say

<p>
  <!--CRLF-->
</p>

If the version passed into the service is not the latest, simply tell that to your user.

This process can be with or without a database, can be with ExternalInterface and the use of JavaScript, it can really be whatever you want.

I seriously recommend using the 1st way to do this unless you really want to make sure that the version your user is seeing is the latest.