0

How can I control what does and doesn't get cached by an applet? Additionally, any insights into how caching works within an applet would be most appreciated.

I'm making a simple request in an applet to try and test if resources loaded at runtime are cached anywhere.

Here's the code that makes the request. I call this several times in a row, all within the same applet lifecycle:

URL url = new URL("http", "localhost", 8343, "/spring-social-test/testSession.html");
            URLConnection connection = url.openConnection();
            connection.setDefaultUseCaches(true);
            connection.connect();

But here's what is output in the Java applet plugin console:

network: Cache entry not found [url: http://localhost:8343/spring-social-test/index.html, version: null]
network: Connecting http://localhost:8343/spring-social-test/index.html with proxy=DIRECT

Update

Just to be clear - I need to know under what circumstances things (images) will get cached, as I'm working on a browser-based game prototype wherein my main cost will be bandwidth. I need to know exactly how much bandwidth I'll be using in order to explore business models.

2 Answers 2

0

Traditionally, applet resources were cached eagerly (before anything else happened). The only way around that was to leave some of the Jars out of the archive attribute and (in a trusted applet) establish an URLClassLoader to load other resources as needed.

But things change. Deploy the applet using Java Web Start and you can have complete control over download behavior on a Jar by Jar basis.

Java Web Start (JWS) is the Oracle Corporation technology used to launch rich client (Swing, AWT, SWT) desktop applications directly from a network or internet link. It offers 'one click' installation for platforms that support Java.

JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..

..

JWS was first offered as a separate download on 14 March 2001 over two years after the release of Java 1.2, and could launch both applications and applets as free floating entities. The functionality became co-bundled with J2SE 1.4.2. Since 1.6.0_10 (the Next Generation Java Plug-In), JWS can also be used to configure applets that remain embedded in a web page.

See an example applet deployed by JWS in this small Animated GIF maker. That applet is deployed using JWS in order to use the JNLP API services that come with it, which allow a sand-boxed applet to access the local file-system.

4
  • Thanks for the idea. I'm working on a browser-based game, so I'm not sure how applicable JWS would be. Will all browsers that support applets also support JWS applications?
    – DeejUK
    Jul 20, 2012 at 8:01
  • Was there some part of "The functionality became co-bundled with J2SE 1.4.2" that you do not understand? Jul 20, 2012 at 8:02
  • 1
    Andrew, thanks for the answer and the clarification, but there's no need to be sarcastic. I'm just trying to get to grips with an area of Java I know little about, and its easy to miss details when inundated with a deluge of new information.
    – DeejUK
    Sep 2, 2012 at 8:04
  • "there's no need to be sarcastic" Sure there is. It helps 'cut through the deluge'. Sep 2, 2012 at 8:26
-1

Do one thing go to ControlPanel>Programs>JAVA>General>Settings>DeleteFiles

Delete cached application and applet. This worked for me.

1
  • Thanks, but this doesn't address the problem I'm trying to solve. I don't want to clear my cache, I want to know under what circumstances resources requested at runtime will be cached.
    – DeejUK
    Jul 20, 2012 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.