在 Acrobar Reader 10.0 (HTTP1.0/HTTP1.1) 中使用 PDF 流时如何防止缓存
我试图找到一种方法来防止浏览器缓存使用流方法加载的 PDF。
FireFox 和 Chorme 可以很好地处理以下标头,并且不会缓存任何 pdf 文件:
Response.AddHeader("Pragma", "no-cache, no-store"); Response.AddHeader("Cache-Control", "无缓存,无存储,必须重新验证,max-age=0"); Response.AddHeader("过期", "-1");
不过,IE 7(使用 acrobat reader 9.4.1)仅适用于以下标头并阻止缓存 PDF 文档:
Response.AddHeader("Pragma", "no-cache, no-store"); Response.AddHeader("Cache-Control", "私有,必须重新验证,max-age=0"); Response.AddHeader("过期", "-1");
当我尝试将 IE 7 与 Acrobat Reader 10 一起使用时,无论我如何尝试,上述标头都没有任何不同,并且缓存了 PDF。
当我尝试放置 Cache-Control: no-cache, no-store 时,pdf 根本没有加载。 据我了解,IE使用缓存机制来加载PDF文档。
是否有人熟悉可以帮助防止 PDF 文档缓存的全局或特定方式(例如通过使用其他标头)?
I was trying to find a way to prevent browsers from caching PDF that is being loaded using a streaming methods.
FireFox and Chorme deals just fine with the following headers and doesn't cache any pdf file:
Response.AddHeader("Pragma", "no-cache, no-store");
Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=0");
Response.AddHeader("Expires", "-1");
Although, IE 7 (with acrobat reader 9.4.1) works only with the following headers and prevent the caching of the PDF doc:
Response.AddHeader("Pragma", "no-cache, no-store");
Response.AddHeader("Cache-Control", "private, must-revalidate, max-age=0");
Response.AddHeader("Expires", "-1");
When i was trying to use IE 7 with Acrobat Reader 10, the above header didn't make any different and cached the PDF no matter what i tried.
When i am trying to put Cache-Control: no-cache, no-store, the pdf was not loaded at all.
According to my understanding, IE use the cache mechanism to load the PDF documents.
Is there anyone familiar with a global or specific way (by using other headers for example) that can help prevent caching of PDF documents?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将随机数添加到 URL(在路径或查询字符串中)。这样,它每次都会下载该文件。您也可以仅在文件已更改时更改数字,例如使用文件的 mtime。
PHP(因为每个人都明白这一点,即使没有人喜欢它):
Add a random number to the URL, either in the path or in the query string. That way, it'll download the file every time. You could also change the number only, if the file has changed, for example using the mtime of the file.
PHP (since everybody understands that, even if nobody likes it):
使用无缓存标头内联显示 PDF(和其他文档类型)的问题已作为错误提交给 Microsoft:http://support.microsoft.com/kb/316431。 IE 在内联读取 PDF 时使用自己的缓存机制。
不幸的是,M$ 的人说这“按设计工作”,用户不应该使用无缓存标头……想想吧。
您可以尝试 VSU 使用 Java PDF 阅读器的想法...我也可能会走这条路。
This issue of showing PDF (and other document types) inline with the use of the no-cache header has been filed as a bug to Microsoft: http://support.microsoft.com/kb/316431. IE uses its own caching mechanism when reading PDFs inline.
Unfortunately, the folks at M$ said this "works as designed" and users should not use the no-cache header... go figure.
You could try VSU's idea of using a Java PDF reader... I may go this route too.
控制管道中的缓存设置并不是万无一失的。另一种方法是在 PDF 文件名中对实时和日期进行编码。
Controlling the cache settings down the pipe is not fool proof. The alternative is to encode the realtime and date in the file name of the PDF.
您可以将时间日期编码到 PDF 的文件名中,以便每次发出请求时文件名都是唯一的。
Response.AddHeader "Content-Disposition","attachment;filename=somename" + CurrentDate() + Currenttime() ".pdf"
CurrentDate 和 CurrentTime 是虚函数。您需要编写该代码。
You can encode the time date into the filename of the PDF so that each time a request is made the filename is unique.
Response.AddHeader "Content-Disposition","attachment;filename=somename" + CurrentDate() + Currenttime() ".pdf"
CurrentDate adn CurrentTime are imaginary functions. You need to write that code.