简体   繁体   中英

Caching Resources Loaded by Java Applet

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.

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.

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

Delete cached application and applet. This worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM