How to use JESI template/fragment model to cache dynamic content

OracleAS Web Cache How-to

Date: October 22, 2003

How to use JESI template/fragment model to cache dynamic content

After completing this How-To you should be able to:
  •   Know about the JESI template/fragment model to cache dynamic content
  •   Use <jesi:template>, <jesi:fragment> tags

Introduction

Oracle JESI tag library provides convenient interface to ESI tags and Edge Sides Include functionality for Web caching. It provides two models to cache dynamic content.

  • Control/ Include model
  • Template/ Fragment model

This How-To explains the template/fragment model. In the template/ fragment model, the web page is split into separate cacheable fragments. JESI template tag is used to enclose the aggregate of all cacheable fragments. JESI template tag and JESI fragment tag are always used together. JESI template model should be used, when a single page has to be split into separate cacheable fragments. If the page need not be split into fragments, JESI control tag can be used to cache the content.

Pre-requisites for running the example

You will need the following to run this example -

  • Oracle Application Server (9.0.3 or above). This can be downloaded from here
  • Oracle JDeveloper (9.0.3 or above). This can be downloaded from here. This is optional and required only if you wish to deploy from JDeveloper.

Description

Each of the fragment and the content outside the fragments, i.e. the template are considered to be independent cacheable objects. All these objects can have different cache policies set. When the fragment expires, ESI processor built within OracleAS Web Cache will request the origin server for that particular fragment.

The example depicts the sales information system. The example displays sales information page, which consists of sales summary for the current year and sales history showing past sales records. For the current year, sales data will be streamed into the system, hence sales summary content has to be updated frequently than the sales history content.

Using the JESI template/fragment model, the sales information page is split into two fragments. Sales summary fragment which has expiration time of 60 seconds and sales history fragment which has expiration of 300 seconds. For demo purpose, sales history fragment has been set as 300 seconds. However these expiration values can be set to higher/lower values.

Following is the code snippet used to split the content into separate cacheable fragments.

.....
<jesi:template cache="yes">
....
  <jesi:fragment cache="yes" expiration="60" maxRemovalDelay="0">
   <%@ include file="salessummary.jsp"%>
</jesi:fragment>
<!-- sales history -->
<jesi:fragment cache="yes" expiration="300" maxRemovalDelay="0">
   <%@ include file="saleshistory.jsp"%>
</jesi:fragment>

    .....
</jesi:template>

The cache poilcy for the template and the fragment is set by the cache attribute. expiration attribute specifies how long the cached object should stay in the cache and maxRemovalDelay attribute specifies how long the document can be served stale after expiration. expiration and maxRemovalDelay are specified in seconds.

Deploying the Sample

The complete source code for this sample is available here. This section discusses the instruction to run the sample application

Step 1Unjar jesitemplate.jar using Winzip, or using the following command:

> jar xvf jesitemplate.jar

This creates a directory jesitemplate.

Step 2

If you are using JDeveloper then, follow these steps

  • Open Oracle9i JDeveloper and use File/Open option to select the jesitemplate.jws from the jesitemplate directory.
  • Next, select Project/Make jesitemplate.jpr from main menu.
  • Create an application server connection
    • Go to Connections -> Application Server Connection. Right Click and click New connection..
    • In step 1, enter connection name and select Oracle9i Application Server
    • In step 2, enter user name and password
    • In step 3, enter Enterprise Manager's host name, port number and Remote Oracle AS home directory(required only if deployed on remote machine).
    • In step 4, click Next and Test the connection. Click Finish button.
  • Now, Right click jesitemplate.deploy and select Deploy to <connection name>, to the application server connection, which you have created in the previous step.
Step 3To deploy the application using EM. follow the steps.
  • Go to EM web site -> default oc4j home.,
  • Choose Deploy EAR file
  • Enter J2EE Application name, Click the Browse button and choose jesitemplate.ear from <SAMPLE_HOME>/deploy/jesitemplate.ear
  • Enter the Application name as jesitemplate and click next
  • Enter URL mapping as /jesitemplate and click Finish
  • Click Deploy to deploy the application.

Running the Sample

Access the page on the browser, using the following URL

http://<host_name>:<port>/jesitemplate/sales.jsp?region=America

where, <host_name> is the machine on which Web Cache is installed and <port> is the port on which Web Cache listener is running.

For Example, http://incq185b.idc.oracle.com:7777/jesitemplate/sales.jsp?region=America

Resources


Please enter your comments about this sample in the OTN Sample Code Discussion Forum.


E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy