How to use JESI invalidate tag to invalidate cached content
OracleAS Web Cache How-to
Date: October 22, 2003
How
to use JESI invalidate tag to invalidate cached content
After
completing this How-To you should be able to:
Use
JESI 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 requests
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. When the cached document is invalidated, the next request to this
document will be fetched from the origin server, cached in cache server and then
served to the browser from the cache server.
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
The
cached content can be invalidated in 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
document explains how to invalidate the cached content using the JESI invalidate
tag. The sample displays a set of randomly generated numbers on every request.
When this page is cached, for every request the page will display the same set
of numbers until the page is invalidated. When the 'Invalidate' button on the
page is clicked, the sample application invalidates the cached content using the
JESI invalidate tag and fetches a new set of numbers.
Following
is the code snippet used to invalidate the cached content.
In the
above code snippet the config attribute of <jesi:invalidate>
tag refers to the jesi.xml, which contains cache server details like
the hostname, invalidation port and the invalidation password. The URI of the
document to be invalidated is listed out using the <jesi:object> tag. maxRemovalDelay
specifies how long (in seconds) the document can remain in the cache after invalidation.
After invalidation, if the document can not be fetched from the origin server,
then the cache server will be able to return the invalid document instead of orgin
server busy error. The default value is '0', meaning the document has to be immediately
removed after invalidation.
Deploying the Sample
The
complete source code for this sample is available here.
This section discusses the instruction to run the sample application
Step 1
Unjar
jesiinvalidate.jar using Winzip, or using the following
command:
> jar xvf jesiinvalidate.jar
This creates a directory jesiinvalidate.
Step 2
If you are using JDeveloper then, follow these steps
Open
Oracle9i JDeveloper and use File/Open option to select the
jesiinvalidate.jws from the jesiinvalidate
directory.
Next, select Project/Make jesiinvalidate.jpr
from main menu.
Edit jesi.xml , change the
following tags
url - Web Cache host name and the invalidation port. By
default invalidation port is 4001.
password - invalidator password. By
default it is invalidator.
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 jesiinvalidate.deploy and select Deploy
to <connection name>, to the application server connection, which you have
created in the previous step.
Step
3
To deploy the application using EM. follow
the steps.
Set Web Cache details for Invalidation
From
the <SAMPLE_HOME>/deploy directory,
Extract jesiinvalidate.ear & jesiinvalidate.war jar
-xvf jesiinvalidate.ear jesiInvalidate.war jar -xvf jesiinvalidate.war WEB-INF/jesi.xml
Edit
<SAMPLE_HOME>/deploy/WEB-INF/jesi.xml , change
the following tags
url - Web Cache host name and the invalidation port.
By default invalidation port is 4001.
password - invalidator password.
By default it is invalidator
Update the ear and war files jar
-uvf jesiinvalidate.war WEB-INF/jesi.xml jar -uvf
jesiinvalidate.ear jesiInvalidate.war
Go
to EM web site -> default oc4j home.,
Choose Deploy EAR file
Enter
J2EE Application name, Click the Browse button and choose jesiinvalidate.ear
from <SAMPLE_HOME>/deploy/jesiinvalidate.ear
Enter
the Application name as jesiinvalidate and click next
Enter URL mapping
as /jesiinvalidate and click Finish
Click Deploy to deploy the application.
Running the Sample
Access
the page on the browser, using the following URL
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/jesiinvalidate/lottery.jsp
Hitting
the 'Fetch Again' button repeatedly, displays the same set of randomly generated
numbers for all requests. This is because the dynamic page is cached in the cache
server and served from the cache server. Hitting 'Invalidate & Fetch' button
invalidates the cached content in the cache server and fetches a new set of randomly
generated numbers.