Sun Java System Web Server 7.0 Update 2 Developer's Guide to Java Web Applications

Caching Elements

For details about response caching as it pertains to servlets, see Caching Servlet Results and JSP Cache Tags.

Caching elements are as follows:

cache Element

This element configures caching for web application components.

Subelements

The following table describes subelements for the cache element.

Table A–29 cache Subelements

Element 

Required 

Description 

cache-helper Element

zero or more 

Specifies a custom class that implements the CacheHelper interface.

default-helper

zero or one 

Allows you to change the properties of the default, built-in cache-helper class.

property Element

zero or more 

Specifies a cache property, which has a name and a value. 

cache-mapping Element

zero or more 

Maps a URL pattern or a servlet name to its cacheability constraints. 

Attributes

The following table describes attributes for the cache element.

Table A–30 cache Attributes

Attribute 

Default Value 

Description 

max-entries

4096

(Optional) Specifies the maximum number of entries the cache can contain. Must be a positive integer. 

timeout-in-seconds

30 

(Optional) Specifies the maximum amount of time in seconds that an entry can remain in the cache after it is created or refreshed. Can be overridden by a timeout element.

enabled

false

(Optional) Determines whether servlet and JSP caching is enabled. Legal values are on, off, yes, no, 1, 0, true, false.

Properties

The following table describes properties for the cache element.

Table A–31 cache Properties

Property Name 

Default Value 

Description 

cacheClassName

com.sun.appserv.web

.cache.LruCache

Specifies the fully qualified name of the class that implements the cache functionality. For a list of valid values, seeCache Class Names.

MultiLRUSegmentSize

4096

Specifies the number of entries in a segment of the cache table that should have its own LRU (least recently used) list. Applicable only if cacheClassName is set to com.sun.appserv.web

.cache.MultiLruCache.

MaxSize

unlimited; Long.MAX_VALUE

Specifies an upper bound on the cache memory size in bytes (KB or MB units). Example values are 32 KB or 2 MB. Applicable only if cacheClassName is set to com.sun.appserv.web.

cache.BoundedMultiLruCache.

Cache Class Names

The following table lists possible values of the cacheClassName property.

Table A–32 cacheClassName Values

Value 

Description 

com.sun.appserv.web.cache.LruCache

A bounded cache with an LRU (least recently used) cache replacement policy. 

com.sun.appserv.web.cache.BaseCache

An unbounded cache suitable if the maximum number of entries is known. 

com.sun.appserv.web.cache.MultiLruCache

A cache suitable for a large number of entries (>4096). Uses the MultiLRUSegmentSize property.

com.sun.appserv.web.cache.BoundedMultiLruCache

A cache suitable for limiting the cache size by memory rather than number of entries. Uses the MaxSize property.

cache-helper Element

This element specifies a class that implements the CacheHelper interface. For details, see CacheHelper Interface.

Subelement

The following table describes the property subelements for the cache-helper element.

Table A–33 cache-helper Subelement

Element 

Required 

Description 

property Element

zero or more 

Specifies a property, which has a name and a value. 

Attributes

The following table describes attributes for the cache-helper element.

Table A–34 cache-helper Attributes

Attribute 

Default Value 

Description 

name

default 

Specifies a unique name for the helper class, which is referenced in the cache-mapping element. 

class-name

none 

Specifies the fully qualified class name of the cache helper, which must implement the com.sun.appserv.web.CacheHelper interface.

default-helper

This element allows you to change the properties of the built-in default cache-helper class.

Subelement

The following table describes the property subelements for the default-helper element.

Table A–35 default-helper Subelements

Element 

Required 

Description 

property Element

zero or more 

Specifies a property, which has a name and a value. 

Attributes

none

Property

The following table describes the cacheKeyGeneratorAttrName properties for the default-helper element.

Table A–36 default-helper Properties

Property Name 

Default Value 

Description 

cacheKeyGeneratorAttrName

Uses the built-in default cache-helper key generation, which concatenates the servlet path with key-field values, if any

The caching engine looks in the ServletContext for an attribute with a name equal to the value specified for this property to determine whether a customized CacheKeyGenerator implementation is used. An application provide a customized key generator rather than using the default helper.

See CacheKeyGenerator Interface .

cache-mapping Element

This element maps a URL pattern or a servlet name to its cacheability constraints.

Subelements

The following table describes subelements for the cache-mapping element.

Table A–37 cache-mapping Subelements

Element  

Required  

Description  

servlet-name Element

requires one servlet-name or url-pattern

Contains the name of a servlet. 

url-pattern Element

requires one servlet-name or url-pattern

Contains a servlet URL pattern for which caching is enabled. 

cache-helper-ref Element

required if timeout, refresh-field,http-method, key-field, and constraint-field are not used

Contains the name of the cache-helper used by the parent cache-mapping element.

cache-mapping Element

zero or more 

Specifies the RequestDispatcher methods for which caching is to be enabled on the target resource. Valid values are REQUEST, FORWARD, INCLUDE, and ERROR (default: REQUEST).  

timeout Element

zero or one if cache-helper-ref is not used

Contains the cache-mapping specific maximum amount of time in seconds that an entry can remain in the cache after it is created or refreshed

refresh-field Element

zero or one if cache-helper-ref is not used

Specifies a field that gives the application component a programmatic way to refresh a cached entry. 

http-method Element

zero or more if cache-helper-ref is not used

Contains an HTTP method that is eligible for caching. 

key-field Element

zero or more if cache-helper-ref is not used

Specifies a component of the key used to look up and extract cache entries. 

constraint-field Element

zero or more if cache-helper-ref is not used

Specifies a cacheability constraint for the given url-pattern or servlet-name.

Attributes

none

url-pattern Element

This element contains data that specifies a servlet URL pattern for which caching is enabled. See the Java Servlet 2.5 specification.

Subelements

none

Attributes

none

cache-helper-ref Element

This element contains data that specifies the name of the cache-helper used by the parent cache-mapping element.

Subelements

none

Attributes

none

timeout Element

Contains data that specifies the cache-mapping specific maximum amount of time in seconds that an entry can remain in the cache after it is created or refreshed. If not specified, the default is the value of the timeout attribute of the cache element.

Subelements

none

Attributes

The following table describes attributes for the timeout element.

Table A–38 timeout Attributes

Attribute 

Default Value 

Description 

name

none 

Specifies the timeout input parameter, whose value is interpreted in seconds. The field's type must be java.lang.Long or java.lang.Integer.

scope

context.attribute

(Optional) Specifies the scope in which the input parameter can be present. Allowed values are context.attribute, request.header, request.parameter, request.cookie, session.id, and session.attribute.

refresh-field Element

This element specifies a field that gives the application component a programmatic way to refresh a cached entry.

Subelements

none

Attributes

The following table describes attributes for the refresh-field element.

Table A–39 refresh-field Attributes

Attribute 

Default Value 

Description 

name

none 

Specifies the input parameter name. If the parameter is present in the specified scope and its value is true, the cache will be refreshed.

scope

request.parameter

(Optional) Specifies the scope in which the input parameter can be present. Allowed values are context.attribute, request.header, request.parameter, request.cookie, session.id, and session.attribute.

http-method Element

This element contains data that specifies an HTTP method that is eligible for caching. The default is GET.

Subelements

none

Attributes

none

key-field Element

Specifies a component of the key used to look up and extract cache entries. The web container looks for the named parameter, or field, in the specified scope.

If this element is not present, the web container uses the Servlet Path, the path section that corresponds to the servlet mapping that activated the current request. See the Servlet 2.5 specification, section SRV 4.4, for details on the Servlet Path.

Subelements

none

Attributes

The following table describes attributes for the key-field element.

Table A–40 key-field Attributes

Attribute 

Default Value 

Description 

name

none 

Specifies the input parameter name. 

scope

request.parameter

(Optional) Specifies the scope in which the input parameter can be present. Allowed values are context.attribute, request.header, request.parameter, request.cookie, session.id, and session.attribute.

constraint-field Element

Specifies a cache ability constraint for the given url-pattern or servlet-name.

All constraint-field constraints must pass for a response to be cached. If value constraints are listed, at least one of them must pass.

Subelement

The following table describes the value subelements for the constraint-field element.

Table A–41 constraint-field Subelements

Element 

Required 

Description 

value Element

zero or more 

Contains a value to be matched to the input parameter value 

Attributes

The following table describes attributes for the constraint-field element.

Table A–42 constraint-field Attributes

Attribute  

Default Value  

Description  

name

none 

Specifies the input parameter name. 

scope

request.parameter

(Optional) Specifies the scope in which the input parameter can be present. Allowed values are context.attribute, request.header, request.parameter, request.cookie, session.id, and session.attribute.

cache-on-match

true 

(Optional) If true, caches the response if matching succeeds. Overrides the same attribute in a value subelement.

cache-on-match-failure

false 

(Optional) If true, caches the response if matching fails. Overrides the same attribute in a value subelement.

value Element

This element specifies the value of the entity

Subelements

none

Attributes

none