Datasheet

Patrick c01.tex V3 - 09/18/2009 12:15pm Page 25
Chapter 1: Building Web Applications in WebLogic
Additional initialization parameters for the
CacheFilter
include the following:
Name The name of the cache. It defaults to the request URI.
Timeout Timeout period for the cached content. It defaults to seconds, but it may be specified in
units of
ms
(milliseconds),
s
(seconds),
m
(minutes),
h
(hours), or
d
(days).
Scope The scope of the cached content. Valid values are request, session, application, and cluster.
Note that
CacheFilter
does not support page scope. It defaults to application scope.
Key The names of request parameters, session attributes, and other variables used to differenti-
ate cached content. The key is supplied using a
scope.name
syntax, with possible scope values of
parameter, request, application, and session. Multiple keys can be supplied, separated by commas.
Vars The names of variables used or calculated by the page that should be cached alongside the
HTTP output. When the cached version of the page is retrieved and used, these cached variables
will be placed in their respective scopes as if the page had executed again. It uses the same syntax
as the key parameter.
Size The maximum number of unique cache entries based on
key
values. It defaults to unlimited.
Max-cache-size The maximum size of a single cache entry. It defaults to 64k.
Very simple JSP pages or servlets may be cacheable using only a
timeout
setting as long as the output
does not depend on any request or session variables. Most pages, however, will require the use of the
key
initialization parameter to create multiple cached versions of the page, one for each value of the key
specified in this setting.
The
CacheTest2.jsp
example program in Listing 1-3 is an example of a page that depends on a single
request parameter,
howmany
, and will require a different cached version of the output for each value of
that parameter.
Listing 1-3: CacheTest2.jsp.
<HTML>
<BODY>
<%
int jj = Integer.parseInt(request.getParameter("howmany"));
System.out.println("Inside JSP page with howmany of " + jj);
%>
<H2>We’re going to count from 1 to <%= jj %><H2>
<%
for (int ii = 1; ii <= jj; ii++) {
out.print(ii + "<br>");
}
%>
</BODY>
</HTML>
The
CacheFilter
would be registered to cache this page content with a dependency on the
howmany
request parameter as follows:
<filter>
<filter-name>CacheFilter2</filter-name>
25