cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject cvs commit: cocoon-2.1/src/scratchpad/webapp/samples scratchpad-samples.xml
Date Tue, 01 Jul 2003 13:51:59 GMT
ghoward     2003/07/01 06:51:59

  Modified:    src/scratchpad/webapp/samples scratchpad-samples.xml
  Added:       src/scratchpad/webapp/samples/eventcache eventcache.xsp
  Scratchpad sample for event-based cache validity
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/scratchpad/webapp/samples/eventcache/eventcache.xsp
  Index: eventcache.xsp
  <?xml version="1.0" encoding="ISO-8859-1"?>
      XSP event-based cache sample.
  <xsp:page language="java"
      // artificial slowdown to make the effects of the cache visible
      final int DELAY_SECS = 2;
      * 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()
         // for our test, pages having the same value of "pageKey" will share
         // the same cache location
         return "" + request.getParameter("pageKey");
      * Generate the validity object, tells the cache how long to
      * keep contents having this key around.  In this case, it will 
      * be until an Event is retrieved matching the NamedEvent created below.
      * 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() {
         return new EventValidity(new NamedEvent(request.getParameter("pageKey")));
      <title>A Cacheable XSP Page (Demonstrating Event-Aware Caching)</title>
      	<para>This xsp page is based on (copied from) the cacheable xsp sample 
      	but there are some important differences.  Read the text below, and the 
      	sitemap and source for more details.
              Hi there! I'm a simple dynamic page generated by XSP (eXtensible Server Pages).
              In order to use this sample property, you must have edited cocoon.roles and

              specified the class for role org.apache.cocoon.caching.Cache is set to be 
              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.
              What you see here has been generated on <b><xsp:expr>new java.util.Date()</xsp:expr></b>.
              I'm cached for every different value of request parameter 'pageKey'.
              Here the value is:
              <b><xsp-request:get-parameter name="pageKey"/></b>.
              If this is not the same as the 'pageKey' parameter in the page URL, we have
a problem.
            All other request parameters do not influence cache status.  
            Unlike other cacheable pages in Cocoon, I can be un-cached by events external

            to Cocoon - for instance, when a database table or row is updated.
            My cache entry will be invalidated (actually, removed) when an event named 
            <i><xsp-request:get-parameter name="pageKey"/></i> occurs. 
This can be manually 
            simulated by clicking 
            	<a><xsp:attribute name="href">?<xsp-request:get-query-string/>&amp;event=<xsp-request:get-parameter
  			<b>NOTE: </b>Because the EventAwareCacheImpl has not yet implemented persistence
for its 
  			mappings, the event mappings will disappear but the cached keys will not.  Until this
  			implemented you will want to clear both the in-memory and persistent store after using

  			this sample.  Once the mapping from the EventAwareCacheImpl is gone, firing the events

  			using the sample action <b>will not</b> clear those cached items.   
            // slowdown page generation.
              try {
                Thread.sleep(DELAY_SECS * 1000L);
              } catch (InterruptedException ie) {
                // Not much that can be done...
          <para>Test links:
                  <li><a target="_new" href="?pageKey=one">pageKey=one</a></li>
                  <li><a target="_new" href="?pageKey=two">pageKey=two</a></li>
                  <li><a target="_new" href="?pageKey=three&amp;other=abc">pageKey=three,
                  <li><a target="_new" href="?pageKey=three&amp;other=xyz">pageKey=three,
  1.1                  cocoon-2.1/src/scratchpad/webapp/samples/eventcache/sitemap.xmap
  Index: sitemap.xmap
  <?xml version="1.0"?>
    CVS $Id$
    Event Cache Sample
  <map:sitemap xmlns:map="">
      <map:generators default="file"/>
      <map:transformers default="xslt"/>
      <map:readers default="resource"/>
      <map:serializers default="html"/>
      <map:matchers default="wildcard"/>
      <map:selectors default="browser"/>
      	<map:action name="cacheevent" src="org.apache.cocoon.acting.CacheEventAction"/>
        <map:match pattern="">
          <map:act type="cacheevent">
          	<map:parameter name="event" value="{request-param:event}"/>
          <map:generate type="serverpages" src="eventcache.xsp"/>
  	    <map:transform src="context://samples/stylesheets/dynamic-page2html.xsl">
  	        <map:parameter name="servletPath" value="{request:servletPath}"/>
  	        <map:parameter name="sitemapURI" value="{request:sitemapURI}"/>
  	        <map:parameter name="contextPath" value="{request:contextPath}"/>
  	        <map:parameter name="file" value="xsp/{1}.xsp"/>
  	        <map:parameter name="remove" value="{0}"/>
  1.10      +8 -1      cocoon-2.1/src/scratchpad/webapp/samples/scratchpad-samples.xml
  Index: scratchpad-samples.xml
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/scratchpad-samples.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- scratchpad-samples.xml	27 Jun 2003 20:10:43 -0000	1.9
  +++ scratchpad-samples.xml	1 Jul 2003 13:51:59 -0000	1.10
  @@ -40,4 +40,11 @@
         A test of the Jelly generator - you have to download and install the jelly.jar first!
  +  <group name="Event Based Cache">
  +  	<sample name="Event Based Cache" href="eventcache/?pageKey=one">
  +  	  A sample demonstrating a new system of cache invalidation based on 
  +  	  events usually external to Cocoon.  Example uses include cache content 
  +  	  until a back-end database is updated, or EJB signals an update.
  +  	</sample>
  +  </group>

View raw message