Caching in Java Applets
Asked Answered
G

3

2

What approaches are available for caching within a Java applet?

I gather that the .jar that makes up the applet will be cached by most browsers.

  • Will this be the case for any dependent .jars used by the applet?
  • If the applet loads resources from a remote URL at runtime, is it correct to assume that this will not be cached by the browser? If it is not cached by the browser, would one be able to implement caching by writing to local storage?
Guayule answered 11/4, 2012 at 9:41 Comment(0)
F
3

Will this be the case for any dependent .jars used by the applet?

Yes, assuming that the dependent JARs are cacheable.

If the applet loads resources from a remote URL at runtime, is it correct to assume that this will not be cached by the browser?

Probably yes. The JVM will probably connect directly to the remote server, and the browser won't see the HTTP request. In addition, the JVM will probably be unaware of the browser's cache organization or location. However, this is all platform dependent.

It is also possible that the JVM could implement its own HTTP cache. AFAIK, current generation Oracle JVMs don't, but it is not inconceivable that future ones might.

If it is not cached by the browser, would one be able to implement caching by writing to local storage?

Only if the applet is signed, and the user has accepted the signature. An applet normally can't read or write local storage.

Frisky answered 11/4, 2012 at 10:56 Comment(5)
Thanks for the answer. Just to clarify the runtime caching behaviour: if my Java applet makes an HTTP request of its own, say to load an image, would that be treated like a resource the browser loads itself, or is the browser circumvented and the the JVM makes the request 'directly'?Guayule
If the JVM sandbox permits the applet to do that, then I think that the browser won't be aware that the request is made. I also think that the JVM won't be able to use the browser's cache directly ... because it won't know how it is organized, or even where it is.Frisky
Thanks for the clarification. You may want to amend your second point to "yes", and then I can mark your answer as correct.Guayule
@Deejay - I see what you mean. I misunderstood that part of your question.Frisky
Hi Stephen, I found another StackOverflow answer that suggests that using URLConnection will go through the browser's cache. See my answer below.Guayule
S
2

For better control of resource caching, deploy the applet using Java Web Start which offers:

..automatic update (including lazy downloads and programmatic control of updates)..

Note that a JWS app. does not need to be trusted to invoke the programmatic updates part of the JNLP API.

Sewer answered 11/4, 2012 at 19:56 Comment(0)
G
0

According to How to disable http caching in applet and URLConnection JavaDoc caching will be enabled when requesting a resource programatically.

Guayule answered 13/4, 2012 at 7:51 Comment(2)
Note that setUseCaches talks about allowing caches to be used. I think it is referring to caching in external HTTP proxies. But feel free to experiment see if this does make use of the browser's cache and/or a JVM specific cache.Frisky
Yep, I think some empirical tinkering is required :)Guayule

© 2022 - 2024 — McMap. All rights reserved.