The cache tag

To cache a portion of a page, surround it with this tag, as in:

<prefix:cache attributes>
... page content ...
</prefix:cache>

Where prefix is the tag prefix that you assigned the tag library when declaring it in the taglib directive in your page source, and attributes is a list of attribute-value pairs to set the attributes described in Table 5-2.

Table 5-2: Cache tag attributes

Attribute

Comments

parameters

A comma-delimited list of request parameters to include in the key. A value of “*” includes all parameters in the key. If not specified, all parameters are included in the key.

attributes

A comma-delimited list of session attributes to include in the key. A value of “*” includes all session attributes. If not specified, no session attributes are included in the key.

messageTopics

A comma-delimited list of message topics to include in the key. If not specified, no message topics are included in the key.

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.

To use this as a key parameter, the EAServer message service must be configured and running.

localeSensitive

Set this attribute to true if locale-sensitive headers are to be included as part of the key. The default is false, which omits locale-sensitive headers from the key.

headers

A comma-delimited list of request headers to include in the key. The default is to include no headers in the key.

timeout

Specifies how long, in seconds, an entry in the cache remains valid. The default value is 600.

name

Allows you to specify a unique name, so that a cache can be shared across multiple pages. If you do not specify a name, the default value is computed so that each page has one cache for all the tags within that page, and each occurrence of the cache tag is assigned an ID that is unique within the page. You can specify a name to cache parts of a response that occur on several pages: data computed on one page can be read from cache and used in another page.

namespace

Specifies what name space the cache is part of. EAServer tracks usage to determine which entry is the least recently used when entries must be removed. Caches in the same name space share the same use statistics, and EAServer evicts the least recently used entry from all the caches in the name space. The default value is “jspfragmentcache” which means unless otherwise specified, every cache is part of the same name space.

scope

Specifies the scope in which data is stored in the cache. Can be either session or application. The value session indicates that only pages in the same session can view the cached data. The default, application, indicates that all pages in the Web application have access to the cached data.

size

Specifies the size for this cache. Once the cache is full, entries are evicted based on a least recently used policy. Size is specified as a string using either Mb for megabytes or Kb for kilobytes, for example “10Mb” means 10 megabytes. If not specified, the default is 1Mb.

When recompiling a JSP, EAServer flushes any cache entries that are used in the page. When refreshing the Web application, EAServer refreshes all caches that are scoped to the application. You can also flush caches programmatically using the flushCacheByKey or flushCacheByScope tags.