Fixing Flash's aggressive caching

2019-05-11 09:11发布

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.

2条回答
唯我独甜
2楼-- · 2019-05-11 10:06

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

查看更多
霸刀☆藐视天下
3楼-- · 2019-05-11 10:09

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!

查看更多
登录 后发表回答