ClassName

atg.droplet.Cache

Component

/atg/dynamo/droplet/Cache

Use the Cache servlet bean to reduce repetitive time-consuming tasks by keeping content in temporary memory. When you use the Cache servlet bean, you specify the content you want cached and how frequently the cache should be cleared. Cached URLs do not retain session or request IDs.

WhichContenttoCache

Caching data resolves many tasks into one. Consider a Switch servlet bean that returns one set of RepositoryItems to females and another set to males. Each time that code is executed two time-consuming tasks occur: the Switch servlet bean is processed and the outcome repositoryItem is retrieved. Embedding the Switch servlet bean in a Cache servlet bean causes the following to occur in future executions: DAF queries only the gender property of the Profile component (which is stored locally) and provides the appropriate content (also stored locally). This example is an ideal candidate for use with the Cache servlet bean because it is involves expensive operations—page computations and querying the database.

In determining whether the Cache servlet bean is appropriate for a given situation, consider the following:

In summary, use the Cache servlet bean to hold content that is expensive to compute, meaning the data you want to cache takes longer to process on its own than it takes to render the Cache servlet bean and resolve its key parameter for that data. A common example is code that renders content from the database for a large subset of your user community. Although you might want Cache to involve some personalization (determining that subset), if you also want to cache programming code, make sure the output is saved by the Cache servlet bean. Avoid the Cache servlet bean in these circumstances:

It is a good idea to measure your page performance with and without the Cache servlet bean as the final determination of its efficiency for a given circumstance.

ClearingtheCache

You can determine how often data is flushed for a given Cache instance on a JSP or for all instances of the Cache servlet bean. To remove cached content associated with a particular instance of Cache, set the cacheCheckSession input parameter in the Cache instance to the frequency by which associated data should be expired. If you omit this parameter, the Cache.defaultCacheCheckSeconds property is used (default value is 60 seconds) .

The Cache.purgeCacheSeconds property sets the frequency by which content cached by any Cache servlet bean should be flushed. The default is 21600 seconds or every 6 hours. Additional cache purging occurs when a JSP is removed or recompiled.

Input Parameters

key
The key parameter lets you have more than one view of content based on some value that uniquely defines the view of the content. For example, if the content is displayed one way for members and another for non-members, you pass in the value of the member trait as the key parameter.

hasNoURLs
Determines how cached URLs are rendered for future requests. By setting hasNoURLs to false, you specify that subsequent requests for the cached content causes URLs to be rewritten on the fly, assuming URL Rewriting is enabled. A setting of false for hasNoURLs causes URLs to be saved and rendered exactly as they are currently (without session or request IDs) regardless of whether URL Rewriting is enabled.

cacheCheckSeconds
Specifies the interval after the content is cached until the cached is regenerated. If no cacheCheckSeconds parameter is supplied, the content is expired using the defaultCacheCheckSeconds property in the Cache servlet bean’s properties file.

Open Parameter

output
The code enclosed by the output open parameter is cached.

Example

This example demonstrates a simple implementation of the Cache servlet bean that displays gender-specific articles to users. The fictitious GenderSpecificArticles servlet bean determines the current user’s gender and then displays one set of articles to men and a different set to women.

This JSP code:

<dsp:droplet name="GenderSpecificArticles">
</dsp:droplet>

renders this content for women:

<a href="womensarticle1.html">women's article 1</a>
<a href="womensarticle2.html">women's article 2</a>

and this content for men:

<a href="mensarticle1.html">men's article 1</a>
<a href="mensarticle2.html">men's article 2</a>

The following example caches the preceding code:

<dsp:droplet name="/atg/dynamo/droplet/Cache">
  <dsp:param bean="Profile.gender" name="key"/>
  <dsp:oparam name="output">
    <dsp:droplet name="GenderSpecificArticles">
    </dsp:droplet>
  </dsp:oparam>
</dsp:droplet>

The Cache servlet bean defines male and female as cache keys. The male key is set to this string:

"<a href="mensarticle1.html">men's article 1</a>
<a href="mensarticle2.html">men's article 2</a>"

The female key is set to this string:

"<a href="womensarticle1.html">women's article 1</a>
<a href="womensarticle2.html">women's article 2</a>"

The first time the JSP holding the Cache servlet bean is rendered, the GenderSpecificArticles servlet bean executes, but future requests for this page simply look up the result of GenderSpecificArticles in the cache and display the appropriate string.

 
loading table of contents...