Control caching of your RIA applications

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.

1st way

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

2nd way

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:

   1: var versionLabel:String = "29Jan2009_01";

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

   1: string finalVersion = "30Jan2009_09";

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.

Avi Tzurel

My name is Avi Tzurel. I'm a professional web developer from Israel. I spend most of my day developing both web products and RIA applications as well as imparting my experience onto others. I speak, teach and write about my passions, and develop applications according to what I preach. I specialize in Flex, Adobe Air, HTML, XHTML, Javascript, jQuery and other Javascript libraries, on the server side I do .net along side with Ruby on Rails. You can connect with me on Twitter or email me through the contact page on this blog.

  • Share/Bookmark
Posted Monday, April 27th, 2009 under Flex.

Leave a Reply