如何URLConnection.setUseCaches()工作在实践中? [英] How does URLConnection.setUseCaches() work in practice?

查看:2306
本文介绍了如何URLConnection.setUseCaches()工作在实践中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个加载了使用URLConnection的HTTP连接图像的小程序。我设置的所有连接setUseCaches(真),但仍然没有看到任何缓存行为。我的形象的HTTP标头有合理的缓存设置。如果你看一下错误4528599 有这个颇具神秘色彩的语句:

I have an Applet which is loading images over a http connection using URLConnection. I am setting setUseCaches(true) for all connections, but still not seeing any caching behavior. My image's HTTP headers have reasonable cache settings. If you look at bug 4528599 there is this rather mysterious statement:

Java的当前版本(1.3.1)插件只检查浏览器的缓存
  文件后缀名为.jar或的.class。有人告诉我,对于Java插件
  1.4浏览器缓存将检查以下文件
  类型:的.class,的.jar,.zip文件,个.jpg,.gif .WAV,.AU

The current version (1.3.1) of Java Plug-In only checks the browser cache for files whose names end in .jar or .class. I have been told that for Java Plug-In 1.4 the browser cache will be checked for the following file types: .class, .jar, .zip, .jpg, .gif, .wav, .au.

当然,这标记为固定的1.6,但即使在1.6我看不到任何缓存。我的图像是PNG文件,并在某些情况下实际上并不使用的.png扩展名结尾英寸我看不到任何缓存。

Of course, this was marked as FIXED for 1.6, but even under 1.6 I don't see any caching. My images are PNG files, and in some cases don't actually end in with a .png extension. I don't see any caching.

有关1.6统一下载引擎的bug修复报告谈判,但谷歌似乎并不很了解。

The bug fix report talks about the 1.6 Unified Download Engine, but google doesn't seem to know much about it.

难道这工作还是它只是另一个破的太阳功能。有什么办法或变通方法,我可以让我的小程序从浏览器缓存加载PNG图像?我想preFER没有实现我自己......

Is this supposed to work or it just another broken Sun "feature". Is there any way or workaround where I can get my applet to load PNG images from the browser cache? I would prefer not to implement my own....

更新:该缓存似乎绑定到 ResponseCache中实现。请参见此技术关于如何工作的更多信息。最后一行说:

UPDATE: The caching seems to be tied to the ResponseCache implementation. See this technote for more info on how that works. The last line says:

有是URLConnection的缓存中没有默认实现
  Java 2标准版。但是,Java插件和Java Webstart的做
  提供对一个开箱即用。

There is no default implementation of URLConnection caching in the Java 2 Standard Edition. However, Java Plugin and Java WebStart do provide one out of the box.

所以,在我看来,该问题真的成为:如何Java插件ResponseCache中实现真正的工作?什么是V1.4 / V1.5 / 16节之间的区别

So it seems to me that the the question really becomes: How does the Java Plugin ResponseCache implementation really work? What are the differences between v1.4/v1.5/v.16

任何人有什么想法?

推荐答案

这个方法很可能只设置在传出请求的HTTP Cache-Control头指令来允许缓存值。假如你叫setUseCaches(假),但会是一个

This method very likely only sets the HTTP Cache-Control header directives in the outgoing request to values that permit caching. Had you called setUseCaches(false), there'd be a

Cache-Control: no-cache

指令为例。要检查这一点,你可以把一个HTTP调试代理服务器的小应用程序和服务器之间,并看看标题。

directive for example. To check this, you could put an HTTP debugging proxy server between your applet and the server and take a look at the headers.

现在只是因为请求说,这是愿意使用缓存,您的服务器可能不被设置为启用它们。也许它不是一个设置在响应与适当长的时间Expires头,或者它设置在禁止缓存响应Cache-Control头。

Now just because the request says it's willing to use caches, your server might not be set up to enable them. Perhaps it's not setting an Expires header with an appropriately long time in the response, or perhaps it's setting a Cache-Control header in the response that prohibits caching.

一些其他的事情来检查:

Some other things to check:


  • HTTPS响应从来不会缓存;

  • 您可能没有客户端和服务器之间的HTTP缓存;

  • 唯一的HTTP缓存是浏览器的缓存,但它可能会被禁用或设置为使用很少的磁盘。

如果这只是一个香草浏览器的Web应用程序的测试,你还愿意要确保你没有击中刷新按钮,因为这相当于设置无缓存。

If this were just a vanilla browser to web application test, you'd also want to make sure you weren't hitting the refresh button, since that's equivalent to setting no-cache.

这篇关于如何URLConnection.setUseCaches()工作在实践中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆