lzm
lzm

Reputation: 837

Fixing Flash's aggressive caching

I have a flash application that loads a big chunk of data that changes occasionally, so I set up my server to send Last-Modified headers and reply with a 304 Not Modified when the client's version is not outdated.

It works fine in every browser, but Flash completely ignores that and caches the resource aggressively. It doesn't even send a request to the server, it just retrieves the cached file from disk when you try to URLLoader.load a previously visited URL.

The workarounds I find on google aren't helpful for me - either you cache forever or redownload the resource every time (changing the URL parameters). I need a mixture of these - redownload when the resource is updated, use cache otherwise.

Upvotes: 3

Views: 1616

Answers (2)

PatrickS
PatrickS

Reputation: 9572

You could use a version number as URL parameter... This way it won't be re-downloaded each time Flash Player loads, only when you actually change the version number

Upvotes: 4

Mims H. Wright
Mims H. Wright

Reputation: 3037

I don't know if this will work but it's worth trying.

You could try appending a cache breaker code to the file request. Normally, you would do this by attaching a random string of characters to the end of the file name e.g. new URLRequest("bigFile.foo?uncache=273095285209750"). For you, instead of using a random string you could use a date object to generate the string. For example...

var now:Date = new Date();
var request:URLRequest = new URLRequest("bigFile.foo?uncache=" + new Date(now.year, now.month, now.date));

That would hopefully force the content to recache once per day (or hour or however often you want). If you need even more granular control, you could write a short server side script to see whether the file has been modified and check that before requesting the huge download.

I hope this helps!

Upvotes: 1

Related Questions