Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 681
lzm Avatar asked Nov 20 '25 20:11

lzm


2 Answers

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

like image 166
PatrickS Avatar answered Nov 23 '25 10:11

PatrickS


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!

like image 32
Mims H. Wright Avatar answered Nov 23 '25 12:11

Mims H. Wright



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!