cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghow...@apache.org
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
                        sitemap.xmap
  Log:
  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.
  
      $Id$
   -->
  
  
  <xsp:page language="java"
            xmlns:xsp="http://apache.org/xsp"
            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.cocoon.caching.validity.EventValidity</xsp:include>
      <xsp:include>org.apache.cocoon.caching.validity.NamedEvent</xsp:include>
      <xsp:include>java.io.Serializable</xsp:include>
  </xsp:structure>
  
  <xsp:logic>
  
      // 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")));
      }
   </xsp:logic>
  
  
    <page>
      <title>A Cacheable XSP Page (Demonstrating Event-Aware Caching)</title>
      <content>
      	<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.
      	</para>
          <para>
              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 
              org.apache.cocoon.caching.impl.EventAwareCacheImpl.
          </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.  
            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.
            <br/>
            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
name="pageKey"/></xsp:attribute>here</a>.
          </para>
  		<para>
  			<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
is 
  			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.   
  		</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="?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,
other=abc</a></li>
                  <li><a target="_new" href="?pageKey=three&amp;other=xyz">pageKey=three,
other=xyz</a></li>
              </ul>
          </para>
      </content>
    </page>
  </xsp:page>
  
  
  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="http://apache.org/cocoon/sitemap/1.0">
    <map:components>
      <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:actions>
      	<map:action name="cacheevent" src="org.apache.cocoon.acting.CacheEventAction"/>
      </map:actions>
    </map:components>
  
    <map:pipelines>
      <map:pipeline>
        <map:match pattern="">
          <map:act type="cacheevent">
          	<map:parameter name="event" value="{request-param:event}"/>
          </map:act>
          <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}"/>
  	    </map:transform>
          <map:serialize/>
        </map:match>
      </map:pipeline>
    </map:pipelines>
  </map:sitemap>
  
  
  
  
  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!
       </sample>
     </group>
  +  <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>
   </samples>
  
  
  

Mime
View raw message