Oracle Application Server 10g: J2EE Deployment and Administration

Cacheability Rules and Invalidation

Establishing detailed cacheability rules and invalidation policies is generally more of a developer's task than an administrator's, although it's the administrator who implements the policy. The objective is to determine which content within the application can be cached and how long it should remain in the cache. Not all content should always be cached and there should be rules to define when a piece of content needs to be refreshed from the origin server. Fortunately, WC does provide the following excellent methods for caching and invalidating content:

Within the WC Manager tool, these features are implemented as rules and controlled by the pages under the Rule Association and Rules for Caching, Personalization, and Compression sections. In the following sections we'll explain these features and show how you can use them within WC.

Default Cache Settings

When WC is installed, it's configured by default to cache basic, static content that you would expect. This makes it useful "out of the box," without having to engage in an exhaustive effort to identify all of the application-specific content to cache. Additionally, WC lays down a basic framework of rules to begin with rather than forcing you to start from scratch. It should be noted that cacheable content is not loaded into the cache when WC is started because there's no "preload" feature; it's loaded the first time it's requested .

By default, WC is configured to cache the objects based on the following file extensions:

If a file with any of these extensions is returned from the origin server, as long as it's not larger than the maximum object size , WC will, by default, cache these files for future requests .

In Figure 19-21 you can see how the default caching rules are defined with the Caching, Personalization, and Compression Rules page.

Figure 19-21: Caching, Personalization, and Compression Rules page

In Figure 19-21 you can see the default rules for caching. From within this page you can create, add, delete, or edit any caching rule. You know that these rules actually work based on Figure 19-19, where you saw multiple JPG and GIF files being cached.

Notice the rules for Compression and the Detailed Settings headings. Compression determines whether or not the content will be compressed during download and in WC. Some objects are already compressed by default so it doesn't make sense to compress them again. The Detailed Settings link provides additional information for each caching rule, comments, and the ability to change settings. It also lists the expiration policy for the content. In Figure 19-22 you can see the details page for HTML documents.

Figure 19-22: Caching, Personalization, and Compression Rule Details page

In Figure 19-22 you can see that \.html?$ , a regular expression, is being used to cache files ending in .htm and .html . Any file with this extension will be cached in a compressed format. After 300 seconds in the cache, it will be removed immediately. To change this rule (to increase the time frame, for example), simply click the Edit button to make modifications.

Expiration Policies

You define the rules for content expiration on the Expiration Policy Definitions page. This page identifies what expiration policies currently exist and which object types they apply to. WC comes with these three default expiration policies for content management:

Each cacheability rule has one of these expiration policies assigned to it. You can add, delete, or modify expiration policies as needed. The duration for an object can be set for the amount of time in the cache or based on the object creation time. Once an object has passed its expiration time period it can either be forcibly removed immediately or it can be refreshed at a later time from the origin server when the system load is less busy.

In Figure 19-23 you can see the editing options available to the 300 second expiration policy.

Figure 19-23: Edit Expiration Policy page

In Figure 19-23 you can see that any file with a .pdf, .js, .css, .html , or .htm extension will only be cached for a maximum of 300 seconds after being cached. After that 300 second period, the object will immediately be removed.

Invalidation Methods

Before implementing WC, it's necessary to determine what content is static enough to be served in accordance with the expiration policies and what content needs to be removed more often. The concern would be a situation in which users receive data that isn't correct and base their business decisions on invalid cached content. Content can be invalidated manually by the administrator or it can be automatically invalidated by WC or the application.

Manual Invalidation

To manually invalidate content, use either the Basic or Advanced Content Invalidation pages located under the Operations section of the WC Manager. Both screens allow you to review the content to be invalidated before actually invalidating it. They also allow you to either remove it immediately or specify a time frame within which you can remove the documents.

The Basic page allows you to remove all cached content or specify an exact URL.

The Advanced page provides greater control over which content is invalidated. Content to be invalidated can be identified based on the following:

The Advanced page provides some intricate search methods for content, but it would be wise to preview the documents before you invalidate them so you can avoid any mistakes with regular expressions.

Automatic Invalidation

No administrator can or should be tasked with invalidating content except in emergency situations; it simply isn't possible to keep up with all the application requests. A far better method is for the developers (who should know their content better than anyone else), to write application triggers that will invalidate content when it changes. These triggers come in the form of

Oracle provides templates for this code in $ORACLE_HOME/webcache/examples and $ORACLE_HOME/webcache/toolkit .

By using the templates and documentation provided in $ORACLE_HOME/webcache/docs , you can develop a logical invalidation policy to ensure that critical, updated content is being provided to the user .

Be sure to work with the developers to determine which components of the application should be cached. Especially with ESI, partial pages, and application-specific invalidation policies, these rules can become complex. Establish baselines of performance prior to implementation, and then after WC implementation in order to quantify the benefits. Finally, be sure to take advantage of the logging and monitoring utilities within WC so you can measure the performance.

Категории