Chapter 7. JEUS WebCache

Table of Contents

7.1. Overview
7.2. JSP Caching
7.2.1. Basic Information
7.2.2. <cache> Tag
7.2.3. Example of Using <jeus:cache>
7.2.4. Using Flush
7.2.5. Using Refresh
7.3. HTTP Response Caching
7.3.1. Configuring Filters

This chapter describes how to use JEUS WebCache to improve the web application performance.

Performance is an important concern for any application, but it becomes a critical factor when the application is a web service that is accessed by thousands of clients simultaneously. There are many ways to improve web service performance.

A resolution from the hardware side is to improve response times by installing more servers and distributing the requests on multiple servers with load balancing. However, this increases costs and the complexity of managing and operating servers due to factors including clustering.

A resolution from the software side is to cache frequently-used data without server scaling. For subsequent requests, applications can use the cached data instead of regenerating the data, which improves response times and increases performance.

This section describes how to use JEUS WebCache in the JEUS system to improve the performance of web applications. The following are the provided caching methods.

Entries that are cached in JEUS WebCache use soft references, which can prevent OutOfMemory errors from occurring.

To make the best use of caching, select pages that are frequently used or incur long response times due to complex database queries as caching targets.

JSP caching improves the performance of web applications by storing parts of JSP pages in JEUS WebCache by using the JSP tag library.

JEUS WebCache uses <jeus:cache> as a user-defined (custom) tag.

When putting a JSP page content in <jeus:cache>, the body content of the tag is created when the first request occurs. The content will be sent in the response to be cached. The cached content will be returned when the next request occurs.

The <jeus:cache> tag can be used as in the following.

<%@ taglib uri=”http://www.tmaxsoft.com/jeuscache” prefix=”jeus” %>

<jeus:cache name=”...” key=”...” scope=”...” timeout=”...” 
    size=”...” async=”...” df=”...”>
   . . . Body content to be cached. . .
</jeus:cache>

The flush attribute uses a self-closing tag (/>) and is described in "7.2.2. <cache> Tag".

The algorithm used in JSP Caching is LRU. If the number of JEUS WebCache entries exceeds the maximum allowed number, the cached entries will be deleted according to the LRU algorithm.

The TLD file (Tag Library Descriptor) is included in the 'jeus.jar' file that is deployed. To send the URI information from the 'jeuscache.tld' file to the JSP engine, 'taglib uri' in the <jeus:cache> tag must be set to 'http://www.tmaxsoft.com/jeuscache'.

The following diagram shows the data structure that is used to cache entries by using the 'name' attribute and the 'name' + 'key' attributes.


In the previous figure, Name1 and Name3 are cached by only using the 'name' attribute as a tag. If the attributes 'name' and 'key' are used as tags, entries are cached like Name2.

The jeuscache.tld file defines the user-defined tag <jeus:cache>. This file is included in jeus.jar and is located in the following path.

jeus/servlet/cache/resource/jeuscache.tld

The following example shows how to configure the <cache> tag in the jeuscache.tld file.


The following describe the attributes of each tag.

JEUS WebCache supports HTTP Response Caching function that caches the entire HTTP response by using servlet filters.

This method is not appropriate for pages are updated dynamically, but is useful for static contents such as image files and PDFs. This method can be used for web pages whose contents do not change or do not change often.

http://www.sample.com/filter/respcacheTest.jsp?key=value

As in the previous example, the entire URI that includes the key and value is used as the entry key. If the key or value are updated dynamically, the response for each URI will be cached.

Caution

Note that the HTTP response is only cached when the HTTP response state is 200 OK (HttpServletResponse.SC_OK). The URI is used as the entry key in JEUS WebCache.

This section describes how to apply HTTP response caching to web applications.

To use HTTP response caching, register a filter in web.xml.

The following example caches responses for all HTTP requests for which the <url-pattern> is '/filter/' for 10 minutes. Note that the jeus.servlet.cache.web.filter.CacheFilter class must be used as the <filter-class>.


The following describe the initialization parameters that are sent to the filter class.

ParameterDescription
timeout

Timeout for caching HTTP responses. The default value is 3600 and the units are in seconds.

This is set in the same way as the 'timeout' attribute for JSP caching, except that HTTP response caching does not provide the flush function. Hence, if 'timeout' is set to '-1', the web application will not expire unless it is undeployed.

lastModified

Option to send the Last-Modified header in the HTTP response. This is used to reduce the load on the web engine.

The browser can ask the web engine if the cached contents have been updated since the last HTTP request. The web engine then compares the If-Modified-Since header information in the HTTP request with the Last-Modified time of the current entry. If there are no changes, the web engine sends an HTTP 302 code (HttpServletResponse.SC_NOT_MODIFIED).

Options are:

  • on: Determine the last modified time during filtering, and send an HTTP 304 code.

  • off: Do not send a 304 code as the HTTP response.

  • initial: Send a 304 code after setting the last modified time to the current time. This is the default value.

expires

Option to send the Expires header information in the response. If the browser uses caching, the cached contents are valid until they expire. They are used for subsequent HTTP requests.

However, if an entry in JEUS WebCache is updated, the new entry will conflict with the entry stored in the browser cache. In this case, set the Expires header information in the web engine to expire the content that is stored in the browser cache, and use the updated entry in the JEUS WebCache.

Options are:

  • on: If a value is set in the filter chain, send the Expires header.

  • off: Do not send the Expires header.

  • time: Add the previous time parameter value to the last-modified value of the HTTP response, set it in the Expires header, and send the response to the client.