Flex 中使用 FileReference 的 download 方法下载文件时的缓存刷新问题

最近在开发 Flex Web 应用程序时,用到了  FileReference 的 download 方法。FileReference 是 flex 实现文件上传下载的类。
文件上传使用 FileReference.upload() 方法,下载使用 FileReference.download() 方法。
文件下载的 server 端程序实际就是把文件内容读出来,然后返回给 client 端。
开发过程中发现一个问题:第一次下载是正确的,但是当文件内容更改之后,下载的还是以前的文件内容,除非重新打开一个
IE web 页面,才能下载到最新的文件。调试过程发现,当在同一个页面第二次下载时,client 端并没有向 server 端发送
新的 HTTP 请求。 根据问题的表象,考虑可能是缓存造成的,解决方法如下:
server 端在发送文件数据时,设置如下参数来取消 client 端对于 HTTP Response 的缓存:

   // Set Cache-Control to no-cache.
   response.setHeader("Cache-Control", "no-cache");
   // Prevent proxy caching.
   response.setHeader("Pragma", "no-cache");
   // Set expiration date to a date in the past.
   response.setDateHeader("Expires", 946080000000L);
   // Force always modified.
   response.setHeader("Last-Modified", (new Date()).toString());
   
   PrintWriter out = response.getWriter();

   out.println( responseXML );

posted @ 2009-07-26 01:02  coding_rabbit  阅读(411)  评论(0编辑  收藏  举报