You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by bd...@apache.org on 2003/05/01 12:08:21 UTC
cvs commit: cocoon-2.1/src/webapp/samples/xsp/xsp cacheable.xsp
bdelacretaz 2003/05/01 03:08:20
Modified: src/webapp/samples/xsp/xsp cacheable.xsp
Log:
cacheable.xsp updated for 2.1 M2-dev
Revision Changes Path
1.2 +92 -47 cocoon-2.1/src/webapp/samples/xsp/xsp/cacheable.xsp
Index: cacheable.xsp
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/webapp/samples/xsp/xsp/cacheable.xsp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- cacheable.xsp 26 Mar 2003 21:21:33 -0000 1.1
+++ cacheable.xsp 1 May 2003 10:08:20 -0000 1.2
@@ -7,64 +7,109 @@
xmlns:xsp-request="http://apache.org/xsp/request/2.0">
<xsp:structure>
-<xsp:include>org.apache.excalibur.source.SourceValidity</xsp:include>
+ <xsp:include>org.apache.excalibur.source.SourceValidity</xsp:include>
+ <xsp:include>org.apache.cocoon.caching.CacheValidityToSourceValidity</xsp:include>
+ <xsp:include>org.apache.cocoon.caching.DeltaTimeCacheValidity</xsp:include>
+ <xsp:include>java.io.Serializable</xsp:include>
</xsp:structure>
<xsp:logic>
+ // how long to keep the contents of this page in cache
+ final int VALIDITY_SECS = 15;
+
+ // artificial slowdown to make the effects of the cache visible
+ final int DELAY_SECS = 2;
+
/**
- * Generate the unique key.
- * This key must be unique inside the space of this XSP page.
- * This method will be invoked before the generateValidity() method.
- *
- * @return The generated key or 0 if the component
- * is currently not cacheable.
- */
- public java.io.Serializable generateKey()
+ * Generate the unique key for the cache.
+ *
+ * This key must be unique inside the space of this XSP page, it is used
+ * to find the page contents in the cache (if getValidity says that the
+ * contents are still valid).
+ *
+ * This method will be invoked before the getValidity() method.
+ *
+ * @return The generated key or null if the component
+ * is currently not cacheable.
+ */
+ public Serializable getKey()
{
- // Generate unique key; add parameters' values here
- return super.generateKey()+request.getParameter("param");
+ // for our test, pages having the same value of "pageKey" will share
+ // the same cache location
+ return "" + request.getParameter("pageKey");
}
-
+
/**
- * Generate the validity object.
- * Before this method can be invoked the generateKey() method
- * will be invoked.
- *
- * @return The generated validity object or null if the
- * component is currently not cacheable.
- */
- public SourceValidity generateValidity() {
- // Check all dependencies here
- java.util.Calendar cal = new java.util.GregorianCalendar();
- cal.add(java.util.Calendar.SECOND, +5); // valid for 5 seconds
- return new
- org.apache.excalibur.source.impl.validity.TimeStampValidity(cal.getTimeInMillis());
+ * Generate the validity object, tells the cache how long to
+ * keep contents having this key around.
+ *
+ * Before this method can be invoked the getKey() method
+ * will be invoked.
+ *
+ * @return The generated validity object or null if the
+ * component is currently not cacheable.
+ */
+ public SourceValidity getValidity() {
+ // keep in cache for VALIDITY_SECS
+ return CacheValidityToSourceValidity.createValidity(
+ new DeltaTimeCacheValidity(0, VALIDITY_SECS));
}
-</xsp:logic>
+ </xsp:logic>
+
<page>
<title>A Cacheable XSP Page</title>
<content>
- <para>Hi there! I'm a simple dynamic page generated by XSP
- (eXtensible Server Pages).</para>
- <para>I'm cached for every different value of request parameter
- 'param'. Value is: <b>
- <xsp-request:get-parameter name="param"/>
- </b></para>
- <para>All other request parameters do not influence cache status, but
- my validity will expire after 5 sec (see source).
- Value of parameter 'other' is: <b>
- <xsp-request:get-parameter name="other"/></b>
- </para>
- <para>Links:
- <ul>
- <li><a href="cacheable?param=one">param=one</a></li>
- <li><a href="cacheable?param=two">param=two</a></li>
- <li><a href="cacheable?param=three&other=abc">param=three, other=abc</a></li>
- <li><a href="cacheable?param=three&other=xyz">param=three, other=xyz</a></li>
- </ul>
- Try two last links with delay 5 sec; and try without delay.
- </para>
+ <para>
+ Hi there! I'm a simple dynamic page generated by XSP (eXtensible Server Pages).
+ </para>
+
+ <para>
+ I need <xsp:expr>DELAY_SECS</xsp:expr> seconds to be generated, so you can tell
+ if I'm being served from the cache or not.
+ <br/>
+ What you see here has been generated on <b><xsp:expr>new java.util.Date()</xsp:expr></b>.
+ </para>
+
+ <para>
+ I'm cached for every different value of request parameter 'pageKey'.
+ <br/>
+ Here the value is:
+ <b><xsp-request:get-parameter name="pageKey"/></b>.
+ <br/>
+ If this is not the same as the 'pageKey' parameter in the page URL, we have a problem.
+ </para>
+
+ <para>
+ All other request parameters do not influence cache status, but
+ my validity will expire after <xsp:expr>VALIDITY_SECS</xsp:expr> seconds (see source).
+ </para>
+
+ <para>
+ Value of parameter 'other' is: <b><xsp:expr>String.valueOf(request.getParameter("other"))</xsp:expr></b>.
+ <br/>
+ This might be different than the URL parameter 'other', in case the version of the page you're
+ seeing was cached from a request having the same 'pageKey' but a different value of 'other'.
+
+ </para>
+
+ <xsp:logic>
+ // slowdown page generation.
+ try {
+ Thread.sleep(DELAY_SECS * 1000L);
+ } catch (InterruptedException ie) {
+ // Not much that can be done...
+ }
+ </xsp:logic>
+
+ <para>Test links:
+ <ul>
+ <li><a target="_new" href="cacheable?pageKey=one">test with pageKey=one</a></li>
+ <li><a target="_new" href="cacheable?pageKey=two">test with pageKey=two</a></li>
+ <li><a target="_new" href="cacheable?pageKey=three&other=abc">test with pageKey=three, other=abc</a></li>
+ <li><a target="_new" href="cacheable?pageKey=three&other=xyz">test with pageKey=three, other=xyz</a></li>
+ </ul>
+ </para>
</content>
</page>
</xsp:page>