How to use ESI invalidate tag to invalidate cached content

OracleAS Web Cache : How to use ESI invalidate tag

Date: January 28, 2003

How to use ESI invalidate tag to invalidate cached content

After completing this How-To you should be able to:
  •   Use ESI invalidate tag to invalidate cached content.

Introduction

OracleAS Web Cache is content-aware cache server, capable of caching both static and dynamic content. Once the document is cached, all the request to the cached document will be served from the cache server until the document is invalidated. The document has to be invalidated, when the content of the document changes. The cached content can be invalidated by using one of the following methods.

  • Time-based - When the cache document expires, based on the expiration policy set for the cached document.
  • Event-based - On occurrence of an application event, which changes the data. Following methods can be used to invalidate cached document.
    • JESI/ESI tags
    • Java API's
    • PL/SQL API's
  • Manually invalidating the pages - using OracleAS Web Cache Administrator tool.

This How-To explains how to invalidate multi version document by using the ESI invalidate tag. The sample displays all the product id's available, in the welcome page. User can select any product id for its detailed information. When the welcome page is submitted, product id is saved in a cookie named productId and passed to display page, display.jsp. The cached display page in Web Cache will have multiple version based on the productid cookie. The display page can be invalidated for the selected product id by clicking on the 'Invalidate' button. This will forward the request to the invalidate page, invalidate.jsp. This invalidate page is responsible to create the invalidation request and to invalidate the page for the selected product id. The code snippet is shown in the next section.

 

Code snippet

Following is the code snippet used to invalidate the cached content.

.....
<esi:invalidate output="yes">
<?xml version = "1.0"?>
 <!DOCTYPE INVALIDATION SYSTEM "http://www.oracle.com/webcache/90400/WCSinvalidation.dtd">
 <INVALIDATION VERSION="WCS-1.1">
       <OBJECT>
         <ADVANCEDSELECTOR URIPREFIX="/technology/EsiInvalidation/"
                           URIEXP="display.jsp"
                           HOST="<%=request.getHeader("host")%>"
                           METHOD="GET">
          <COOKIE NAME="productId"
                  VALUE="<%=productId%>"/>
         </ADVANCEDSELECTOR>
      <ACTION REMOVALTTL="0"/>
      </OBJECT>
 </INVALIDATION>
</esi:invalidate>
....

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.

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 EsiInvalidation.jar using Winzip, or using the following command:

> jar xvf EsiInvalidation.jar

This creates a directory EsiInvalidation.

Step 2

If you are using JDeveloper then, follow these steps

  • Open Oracle9i JDeveloper and use File/Open option to select the EsiInvalidation.jws from the EsiInvalidation directory.
  • Next, select Project/Make EsiInvalidation.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 EsiInvalidation.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 EsiInvalidation.ear from <SAMPLE_HOME>/deploy/EsiInvalidation.ear.
  • Enter the Application name as Personalize and click next.
  • Enter URL mapping as /EsiInvalidation and click Finish.
  • Click Deploy to deploy the application.
Step 4 Configuring the OracleAS Web Cache for multi version document.
  • Start the OracleAS Web Cache Admin Tool using the browser. By default the administration port is 4000. Access the Admin tool on the browser using the url.
    http://<hostname>:4000/webcacheadmin/ , where <hostname> is the machine on which OracleAS is installed.
    For example, http://incq185b.idc.oracle.com:4000/webcacheadmin
    Login as "administrator". The default password is 'administrator'.
  • Select 'Cookie Definitions' link under 'Rules for Caching, Personalization, and Compression' section.
    a) Click on 'Add' button to create new cookie definition
    b) 'Enter the cookie name' as 'productId' and select 'No' option for 'Also cache documents whose requests do not contain this cookie?'.
  • Now select 'Caching, Personalization, and Compression Rules' link under 'Rules for Caching, Personalization, and Compression' section.
    a) Click on 'Create Global Rule'.
    b) In 'URL Expression' window enter 'EsiInvalidation/display\.jsp'.
    c) Click 'GET' check box option in front of 'HTTP Method(s)'.
    d) Select 'Cache' radio button in front of 'Caching Policy'.
    e) Check the 'productId: no cache w/o cookie' check box in front of 'Multiple Documents with the Same Selector by Cookies' and click 'Submit;'
  • Apply the changes by clicking the 'Apply Changes' button on top. Choose 'Cache Operations' link under 'Operations'.
  • Restart the Web Cache.

Running the Sample

Access the page on the browser, using the following URL

http://<host_name>:<port>/EsiInvalidation/welcome.html.

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/EsiInvalidation/welcome.html

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