0

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!

4

4 回答 4

2

我看到了一些可能的解决方案:

  1. 编写一些 shell 脚本,将磁盘中的临时文件从缓存中删除(您使用的是什么浏览器?)。如果浏览器将它们缓存在内存中,我不确定删除磁盘上的文件是否一定会起作用。
  2. 使用和 HTTP 标头 (No-Cache) 来避免在浏览器中缓存,Adobe 有关于 No-Cache 的文档。您只能在开发模式下设置此标头,以便在生产中缓存 swf。
  3. 根据您的浏览器,强制页面和缓存刷新(例如 Firefox 中的 Crtl-F5)
于 2009-11-11T00:38:41.020 回答
1

我不确定你是如何加载 xml 数据的,但在过去,我通过在 xml 文件的路径中附加一个随机数来解决这个问题:

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

基本上,Flash 会一直认为该文件是一个不同的 URL。它将无法在您的缓存中找到匹配项。

同样,我不确定您是如何加载 XML 数据的,所以我不确定这是否适用于您的情况。

不过,希望它有所帮助。

于 2009-11-11T02:00:45.660 回答
0

您无法重置浏览器缓存,即使您有时会这样做还不够,因为缓存不仅可以发生在服务器和/或客户端上,还可以发生在您的响应从服务器到客户端的途中经过的任意数量的节点上.

您可以使用的唯一工具是缓存标头。

您可以将它们设置为 NoCache 只是记住它每次都会访问服务器

于 2009-11-11T01:03:37.707 回答
0

由于您使用的是 Safari,这里有一篇描述如何使用 AppleScript 清除缓存的文章。但是您可能可以跳过 AppleScript 部分并直接在 rake 任务中删除文件。唯一的问题可能是您必须重新启动浏览器才能使其生效,但这可以通过终止进程和“打开 /Applications/Safari.app”来完成(我假设您在Mac;在 Windows 中,它类似于 start "c:\program files\Safari...")。

于 2009-11-11T05:36:03.510 回答