This section describes the applet caching of JBK Plugin.
By default, JBK Plugin uses the browser cache. As described in '2.3.6 How JBK Plugin Downloads Class Files', when JBK Plugin uses browser functionality for downloading files, they are stored in the browser cache. The browser cache is, however, sometimes cleared because of the limitation of the cache capacity. This causes extra download, though the downloaded file is not actually updated.
To prevent this, JBK Plugin provides its own applet cache. When the applet cache is enabled, the applet is not stored in the browser cache, but stored in the applet cache. JBK Plugin does not automatically clear the applet cache. Therefore, the extra download does not occur. If the user feels inconvenience for the browser cache, we recommend the JBK Plugin applet cache.
Requirements for the Applet Caching
JBK Plugin applet cache is available under the following requirements:
HTTP protocol and HTTPS protocol are available.
By default, the following kinds of files can be stored.
Class files downloaded from the Web server.
JAR files specified in ARCHIVE attribute of the JBK Plugin tag in the HTML file.
For the detail of the JBK Plugin tag, see '2.2.3 How to Create an HTML File for JBK Plugin'.
Image files (GIF, JPEG, and so on) downloaded by invoking java.applet.Applet.getImage().
If the user wants to store the other kinds of files into the applet cache, see 'JBK Plugin Applet Caching API'.
Setting for the Applet Caching
To enable the applet cache, code the following line in the jbkplugin.properties file.
jbk.plugin.www.plugin_cache.enable=<applet-cache-used-or-not> |
Specify the following information in the properties:
jbk.plugin.www.plugin_cache.enable
This property specifies whether the applet cache is enabled. As <applet-cache-used-or-not>, code either of the following:
The applet cache is enabled.
The applet cache is disabled.
By default, the value of this property is set to false. When this property is set to false, the following properties are invalid.
jbk.plugin.www.plugin_cache.dir
This property specifies the applet cache folder. As <applet-cache-folder>, specify the full path name of the applet cache folder. By default, the applet cache folder is set as follows:
${user.home}\applet_cache |
${user.home} means user profile folder.
jbk.plugin.www.plugin_cache.dir.freespace
This property specifies the free space of the applet cache folder. If the drive of the applet cache folder does not have enough free space, that is, if the free space is equal to or less than the value of this property, JBK Plugin does not store the downloaded file into the applet cache.
As <applet-cache-folder-free-space>, the user can specify either of the following:
Absolute value
Numerical value means the free space by bytes. If the user wants to specify the free space by kilobytes, s/he can append 'K' or 'k' to the value. 'M' and 'm' is also available for megabytes.
Relative value
If the user appends '%' to the value, the value is used as the percentage for the total disk capacity.
By default, the value of this property is set to '1%'.
Example
Examples of specifying the size of the allowable space
# by bytes |
jbk.plugin.www.plugin_cache.update
This property specifies the update policy of the applet cache. The following two values can be set.
Updates the cache if the modification time of the file on the Web server is newer than that of the file in the applet cache.
Updates the cache if the modification time of the file on the Web server is different from that of the file in the applet cache.
By default, the value of this property is set to 'newer'.
jbk.plugin.www.plugin_cache.accelerate
This property specifies to use accelerate mode or not when the update policy of the applet cache is set to "newer". The following two values can be set.
When connect to the Web server, JBK Plugin issues the HTTP requests with "If-Modified-Since:" header. If the applet is not necessary to update, the amount of the response from the server can be reduced, and the performance is better.
Issues the HTTP request normally. If cache is available, JBK Plugin stops reading from the server, and reads data from cache file.
By default, the value of this property is set to 'false'.
How to the Applet Caching Works
The applet cache of JBK Plugin works as follows:
If the file is not in the applet cache, JBK Plugin downloads it from the Web server and stores in the applet cache.
If the file is in the applet cache, JBK Plugin checks its modification time and its file size.
JBK Plugin checks the modification time according to the update policy specified by 'jbk.plugin.www.plugin_cache.update'. If the file needs to be updated, JBK Plugin downloads it and updates the cache.
Also, JBK Plugin checks the file size. If the size of the file in the applet cache is different from that of the file on the Web server, JBK Plugin downloads it and updates the cache.
In other cases, JBK Plugin does not download the file and load it from the cache.
When jbk.plugin.www.plugin_cache.accelerate is set to "true", if the cache is available, JBK Plugin asks the Web server with "If-Modified-Since:" header. If the response code is "304 Not Modified", JBK Plugin use the cache.
JBK Plugin does not delete the file in the applet cache. If the user wants to delete the file in the cache, s/he has to do so manually.
If the drive of the applet cache folder does not have enough free space (see the setting of 'jbk.plugin.www.plugin_cache.dir.freespace'), JBK Plugin does not store the downloaded file into the applet cache. Even in this case, the file can be downloaded with no problem and the applet runs normally.
JBK Plugin Applet Caching API
To keep the consistency of the applet cache, it must be guaranteed that several threads do not download the same file at the same time. It is guaranteed that Java VM downloads class files, JAR files and image files only from one thread at a time. Therefore, JBK Plugin makes the applet cache enable for only these kinds of files. For the other kinds of files, the user can use JBK Plugin applet caching API to store them into the applet cache. However, the user has to guarantee that those files are downloaded only from one thread at a time.
JBK Plugin applet caching API is as follows:
Class
com.fujitsu.jbk.plugin.browser.www.PluginCacheController
(extends java.lang.Object)
Methods
getInstance
returns an instance of PluginCacheController.
public static PluginCacheController getInstance() |
An instance of PluginCacheController
getCachedURL
makes the file of the given URL enable to be stored into the applet cache.
public URL getCachedURL(URL origURL) |
the URL of the file to be stored into the applet cache.
A new URL object that represents the same URL as origURL. The new URL object has the functionality of storing the file into the applet cache. The user can use the new URL object for downloading the file. Then JBK Plugin automatically stores the file into the applet cache.
The class file of the PluginCacheController class is stored in the JBK runtime class directory (the JBK runtime class directory is the "classes" directory below the JBK install directory).
When compiling an applet class using it, check that the class path includes the JBK runtime class directory.
Example
An example of downloading a file
not using JBK Plugin applet caching API
// create a new URL object URL url = new URL(/* the URL of the file to be downloaded */); // get a URLConnection URLConnection conn = url.openConnection(); // get an input stream InputStream in = conn.getInputStream(); /* downloading the file by the input stream (omitted) */ |
using JBK Plugin applet caching API
// import import com.fujitsu.jbk.plugin.browser.www.PluginCacheController; |
// creates a new URL object URL url = new URL(/* the URL of the file to be downloaded */); // get a new URL object for applet caching try { url = PluginCacheController.getInstance().getCachedURL(url); } catch (Throwable ignore) { // The exception thrown by getCachedURL() can be ignored. } // get a URLConnection URLConnection conn = url.openConnection(); // get an input stream InputStream in = conn.getInputStream(); /* downloading the file by the input stream (omitted) */ |
Other Topics for the Applet Caching
The files stored in the JBK Plugin applet cache are not stored in the browser cache.
JBK Plugin does not automatically delete the files in the applet cache. If the user wants to delete the files in the applet cache, exit all the browsers that JBK Plugin is running in, and then, delete the files manually.
The applet caching files will be downloaded in the following timing.
For class files, JAR files and image files, JBK Plugin checks the modification time and the file size only at the first time that the file is used in the VM.
For the files that uses the applet caching API, JBK Plugin checks the modification time and the file size when getInputStream() (java.net.URLConnection) is invoked for the file.
HTML files downloaded by showDocument() (java.applet.Applet) are never stored in the applet cache. These HTML files are always stored in the browser cache.
When the following setting exists in the HTTP response header returned from the Web server, JBK Plugin does not store the file into the applet cache:
'no-cache' in the 'Pragma' field
'no-cache' or 'no-store' in the 'Cache-Control' field
'max-age' in the 'Cache-Control' field has no effect for the JBK Plugin applet cache.
For the detail of the HTTP response header, see HTTP/1.1 specification.
In the applet cache folder, JBK Plugin creates a file for cache management, whose name is 'PluginCacheController.ini'. The user should not edit this file, or the applet cache does not work correctly.
If the applet caching function is being used in Windows Vista or Windows 7, the user should set the cache folder belongs to the LocalLow folder at user profile folder.
If GET is used to request the Web server for a file, the file is saved to Applet Caching of JBK Plugin. If POST is used, the file is not saved to this cache.
If the HTTP header that is returned from the Web server during a file download does not include the Last-Modified field or Content-Length field, the file is not saved to Applet Caching of JBK Plugin.