views:

292

answers:

4

I would like to create a rake task or something to clear the browser cache. The issue is, I am running a Flash app, and if I change the data, I more often than not need to reset the browser cache so it removes the old swf and can see the new xml data.

How do you reset the browser cache with ruby? Or even more precisely, how can I only remove a select item from the browser cache?

Thanks for the help!

+2  A: 

I see a few possible solutions:

  1. Write some shell script that deletes the temporary files from disk out the cache (what browser are you using?). I'm am not sure deleting the files on disk will necessarily work if the browser has them cached in memory.
  2. Use and HTTP header (No-Cache) to avoid caching in the browser, Adobe has documentation on No-Cache. You could set this header only in development mode, so that in production the swf is cached.
  3. Depending on your browser, force a page and cache refresh (e.g. Crtl-F5 in Firefox)
John Paulett
thanks! i'm using safari
viatropos
A: 

You cannot reset browser cache, even if you would sometimes it will not be sufficient because caching can occur not only on the server and/or client, but also on any number of nodes your response goes through on its way from your server to your client.

The only tool at your disposal is the caching headers.

You can set them to NoCache just keep in mind that it will be hitting the server every time

mfeingold
+1  A: 

I'm not sure how you're loading the xml data, but in the past, I've gotten around the issue by appending a random number to the path of the xml file:

xml.load("data.xml?"+Math.random());

Basically, Flash will always think the file is a different URL. It won't be able to find a match in your cache.

Again, I'm not sure how you're loading the XML data, so I'm not sure if this applies to your situation.

Hope it helps, though.

Eric
sick, that's nice. thanks!
viatropos
A: 

Since you're using Safari, here's an article describing how to use AppleScript to clear the cache. But you can probably just skip the AppleScript part and remove the files directly in the rake task. The only catch might be that you have to restart the browser for it to take affect, but that could be done with a kill on the process and an "open /Applications/Safari.app" (I'm assuming you're on a Mac; in Windows it would be something like start "c:\program files\Safari...").

Brian Deterling