Chapter 5 Web Application Tuning
Dynamic page caching decreases a servlet's or JSP's response times by caching the output with a multi-part, user-configured key value. This caching mechanism stores responses in their entirety. For pages that return both volatile content and content that rarely changes, use partial page caching instead—see "Using partial page caching".
When page caching is enabled for a servlet or JSP, EAServer checks the cache before invoking the Web component, looking for an entry that matches the key that you have defined for the servlet or JSP. If an appropriate response is found in the cache, EAServer returns the contents of the cache, instead of calling the servlet. If the cache contains no matching key, EAServer invokes the servlet, and caches the response and response headers while returning them to the client.
You can define the key that EAServer uses to store and retrieve cached entries. By default, a key consists of only the servlet's or JSP's location on disk. You can further refine key values by adding up to six optional parameters. Doing so allows caching of separate responses from the same servlet or JSP, based on request characteristics such as locale or HTTP session ID. In addition, you can configure a timeout for cache entries associated with the JSP or servlet to prevent the use of stale data. If you do not require this level of refinement in the cache key, consider using the servlet Java cache instead—see "Using the servlet Java cache".
Use EAServer Manager to enable caching for your servlets and JSPs. To enable caching for JSPs, you must have a Web component defined for the JSP in EAServer Manager. To configure default values for the Web component caching properties, see "Configuring Web application page caching properties".
To configure page caching for a servlet or JSP:
| Parameter | Description |
|---|---|
| Cache Timeout | Enter the number of seconds to keep the Web component's content in the cache; the default is 600; a value of 0 indicates no timeout. The timeout value is stored in the com.sybase.jaguar.servlet.cache.timeout property. |
| Session Local | To include the session ID in the key, select this option; by default, it is not included. The session ID can identify session specific items, such as shopping carts. The value is saved in the com.sybase.jaguar.servlet.cache.use-sessionid property. |
| Locale Sensitive | Select to include the accept-languages header in the key; by default, it is not included. The value is saved in the com.sybase.jaguar.servlet.cache.locale-sensitive property. |
| Request Parameters | To include request parameters in the
key, enter the parameter names as a comma-separated list.
To include all the request parameters, select the Enable All box;
it is selected by default. A single servlet can produce different responses
based on which parameters it receives. A key that includes the request
parameters allows different responses from the same servlet to be cached
separately. The request parameters are saved in the com.sybase.jaguar.servlet.cache.request-parameters property. |
| Session Attributes | To include session attributes in the key, enter the attributes as a comma-separated list. To include all the session attributes, check the Enable All box. The session attributes list is saved in the com.sybase.jaguar.servlet.cache.session-attributes property. |
| Request Headers | To include request headers in the key,
enter the header names as a comma-separated list. For example,
if you include the date header, EAServer looks
for cache entries whose date headers match the request's
date header. The request headers list is saved in the com.sybase.jaguar.servlet.cache.request-headers property. |
| Message Topics | For a key that includes the number of
times a message has been published to a particular topic, enter
the message topic. To use this as a key parameter, the message service
must be configured; for details, see Chapter 31, "Using
the Message Service."
This option is useful when a servlet constructs its response based on the values in a database table. A database trigger can be used to call the message service and publish a message to the topic each time the database table is updated. When a servlet or JSP is requested, EAServer can call the message service's getStatistics method to get the total number of messages published to the topic and compare the value to those in the cache entries. The message topics are stored in the com.sybase.jaguar.servlet.cache.message-topics
property.
|
You can configure page caching for a Web application, as well as for a Web component. EAServer first checks the component-level page caching properties, and if none exists, checks the application-level properties. In other words, the Web application settings serve as defaults for the Web component properties described in "Configuring page caching for servlets and JSPs".
Configuring page caching for a Web application
By default, page caching is disabled, and you cannot
enable page caching at the Web application-level.
To use page caching for a JSP that forwards request to, or dynamically includes, other JSPs or static files, consider these factors. By default, when you enable page caching for a JSP Web component, only its content is cached. If a JSP includes, or forwards requests to, other pages or static files, their output is not cached. To include the output of all the pages or files that are invoked, you can select to cache a Web component's entire tree. This example illustrates portions of three JSP files; two use the <jsp:include> tag to include other JSPs:
// page1.jsp <HTML> <H1>This is page 1</H1></p> <jsp:include page="/page2.jsp" /> </HTML> // page2.jsp <HTML> <H2>This is page 2</H2></p> <jsp:include page="/page3.jsp" /> </HTML> // page3.jsp <HTML> <H3>This is page 3</H3></p> </HTML>If you enable page caching for the Web component mapped to page1.jsp and choose to cache the entire tree, the cached entry displays this in the browser:
This is page 1 This is page 2 This is page 3If you enable page caching for page1.jsp but not for the entire tree, the cached entry displays this in the browser:
This is page 1
When a client requests the Web component mapped to page1.jsp and it is configured to cache the entire tree, the output from page1.jsp, page2.jsp, and page3.jsp is cached as a single entry. EAServer creates a separate cache entry for a single page when:
When using page caching with filters that wrap a servlet response, EAServer must have access to the response. To provide access to the response, the wrapper must implement a getResponse method that returns a ServletResponse object. To implement the wrapper, you can either:
Also, EAServer caches a servlet response immediately after the servlet executes. Therefore, if a filter modifies a response after the servlet executes, the modifications are not saved to the cache.
For more information about creating and using filters, see Chapter 23, "Using Filters and Event Listeners," in the EAServer Programmer's Guide.
| Copyright (C) 2004. Sybase Inc. All rights reserved. |
| |