You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@cocoon.apache.org by da...@cocoon.zones.apache.org on 2006/05/08 18:22:25 UTC

[DAISY] Updated: ExpiresCachingProcessingPipeline

A document has been updated:

http://cocoon.zones.apache.org/daisy/documentation/939.html

Document ID: 939
Branch: main
Language: default
Name: ExpiresCachingProcessingPipeline (unchanged)
Document Type: Sitemap Component (unchanged)
Updated on: 5/8/06 4:22:10 PM
Updated by: ard schrijvers

A new version has been created, state: draft

Parts
=====
Short description
-----------------
This part has been added.
Mime type: text/xml
File name: null
Size: 5956 bytes
Content:
<html>
<body>

<h1>Intro</h1>

<p>This pipeline implementation caches the complete content for a defined period
of time (expires).  You use this caching strategy, when you know your result is
valid for example at least an hour. Since cocoon 2.1.9 (before this version,
despite the fact that the ExpiresCachingProcessingPipeline only has to take its
own cachekey and expiresValidity into account, it checked all cachekeys and
validities of pipelines it used), this is by far the fastest caching strategy,
because you define the exact cache key to be used by the expires pipeline AND
you define how long it is valid after the first call: This means, and this only
holds for the ExpiresCachingProcessingPipeline, that the validities and cache
keys of other pipelines that it includes with map:part/map:generate won't have
to evaluated.</p>

<h1>Declaration</h1>

<p>Make sure you declare the ExpiresCachingProcessingPipeline in your sitemap's
component section in map:pipes:</p>

<p>&lt;map:pipe name="expires"
src="org.apache.cocoon.components.pipeline.impl.ExpiresCachingProcessingPipeline"&gt;
<br/>
   &lt;parameter name="cache-expires" value="180"/&gt; &lt;!-- Expires in
seconds --&gt;<br/>
 &lt;/map:pipe&gt;</p>

<p>The value can also be written like:</p>

<pre>access plus 1 minutes
access plus 1 hours
access plus 1 month
access plus 4 weeks
access plus 30 days
access plus 1 month 15 days 2 hours</pre>

<p>The value of the parameter is in a format borrowed from the Apache HTTP
module mod_expires.</p>

<h1>Usage</h1>

<p>In cocoon, you can define a different cache strategy for every pipeline.
After adding the declaration above, you can use the "expires" pipeline:</p>

<p>&lt;map:pipeline  type="expires" internal-only="false"&gt;<br/>
    &lt;map:match pattern="foo"&gt;<br/>
          &lt;map:generate src="bar.xml" type="jx"&gt;<br/>
             &lt;map:parameter name="time" value="{date:yyyyMMddHHmmss}"/&gt;
<br/>
          &lt;/map:generate&gt;<br/>
          &lt;map:serialize type="xml"/&gt;<br/>
    &lt;/map:match&gt;<br/>
&lt;/map:pipeline&gt;</p>

<p>If bar.xml would look like
&lt;time&gt;${cocoon.parameters.time}&lt;/time&gt;, and you would refresh it
again and again, you would get the same output for 3 minutes (180 seconds from
the declaration in map:components). After 3 minutes, it would result in a new
output, again caching it for 3 minutes. The above map:pipeline is the most basic
example.</p>

<p>If you want to have different cache-expires in different map:pipelines, then
you add a map:parameter with name cache-expires directly under the map:pipeline
of type expires:</p>

<p>&lt;map:pipeline  type="expires" internal-only="false"&gt;<br/>
    &lt;map:parameter name="cache-expires" value="60"/&gt;<br/>
    &lt;map:match pattern="foo2"&gt;<br/>
          &lt;map:generate src="bar.xml" type="jx"&gt;<br/>
             &lt;map:parameter name="time" value="{date:yyyyMMddHHmmss}"/&gt;
<br/>
          &lt;/map:generate&gt;<br/>
          &lt;map:serialize type="xml"/&gt;<br/>
    &lt;/map:match&gt;<br/>
&lt;/map:pipeline&gt;</p>

<p>The match "foo2" will be cached for 1 minute.</p>

<p>With the example above, all urls "/foo", "/foo?bar=1", "foo?bar=1&amp;foo=2"
will be expired under the same cache key. So having the following sitemap block,
</p>

<p>&lt;map:pipeline  type="expires" internal-only="false"&gt;<br/>
    &lt;map:parameter name="cache-expires" value="60"/&gt;<br/>
    &lt;map:match pattern="foo2"&gt;<br/>
          &lt;map:generate src="bar.xml" type="jx"&gt;<br/>
             &lt;map:parameter name="time" value="{date:yyyyMMddHHmmss}"/&gt;
<br/>
             &lt;map:parameter name="bar" value="{request-param:bar}"/&gt;<br/>
          &lt;/map:generate&gt;<br/>
          &lt;map:serialize type="xml"/&gt;<br/>
    &lt;/map:match&gt;<br/>
&lt;/map:pipeline&gt;</p>

<p>and bar.xml
&lt;time&gt;${cocoon.parameters.time}-${cocoon.parameters.bar}&lt;/time&gt;,
would have the same result for three minutes for every link above. This is
because the cache-key of the expires pipeline, is by DEFAULT the sitemap uri!
But, you can define how your cache-key is constructed for every the
map:pipeline:</p>

<p>&lt;map:pipeline  type="expires" internal-only="false"&gt;<br/>
    &lt;map:parameter name="cache-expires" value="60"/&gt;<br/>
    &lt;map:parameter name="cache-key" value="{0}"/&gt;<br/>
       .......</p>

<p>&lt;/map:pipeline&gt;</p>

<p>The above, is how it behaves by default, since {0} refers to the sitemap uri.
But, you can also construct your cache-key like:</p>

<p>&lt;map:pipeline  type="expires" internal-only="false"&gt;<br/>
    &lt;map:parameter name="cache-expires" value="60"/&gt;<br/>
    &lt;map:parameter name="cache-key"
value="{0}{request-param:bar}{session-attr:locale}"/&gt;<br/>
       .......</p>

<p>&lt;/map:pipeline&gt;</p>

<p>Now, your cache-key is different for different locale sessions and parameters
bar.</p>

<h1>Purging your cache</h1>

<p>The last thing about this caching mechanism, is that you can you can use
purge-cache parameter. This is particularly useful, when you want for example a
very large cache-expires value, and purge the cache only when a specific request
comes in. Then, for example, you could use</p>

<p>&lt;map:pipeline  type="expires" internal-only="false"&gt;<br/>
    &lt;map:parameter name="cache-expires" value="600000"/&gt; &lt;!--very long
--&gt;<br/>
    &lt;map:parameter name="cache-key"
value="{0}{request-param:bar}{session-attr:locale}"/&gt;<br/>
    &lt;map:parameter name="purge-cache" value="{request-param:purge}"/&gt;
<br/>
       .......</p>

<p>&lt;/map:pipeline&gt;</p>

<p>Now, if a request comes in with  a parameter purge=true, the specific cache
related to the cache-key is purged, and the content is re-evaluated</p>

</body>
</html>


Fields
======
no changes

Links
=====
no changes

Custom Fields
=============
no changes

Collections
===========
no changes