Archive for the ‘Cocoon’ Category

How to cache match in cocoon

Wednesday, July 13th, 2005

Hi,
if you have need to cache for some time a match you can use two mode, one for a external match, and another for the internal-use match.

External match
In this case you can use the expire of pipeline, but this was a simply http header that was recognized from ISP’s proxy server.

An example:


<map:pipeline>
  <map:parameter name="expires" value="access plus 1 minutes"/>
  ...
</map:pipeline>

So all the match declared in this pipeline was cached for 1 minute from the first access, and so on for all the next access.

Internal match
For the internal match a good solution could be the cache-include of CIncludeTransformer

An example:


<map:match pattern="cached-items-list">
  <map:generate src="resources/xml/include-items-list.xml"/>
  <map:transform type="cinclude">
    <map:parameter name="expires" value="60"/>
  </map:transform>
  <map:serialize type="xml"/>
</map:match>


include-items-list.xml:

<?xml version="1.0" encoding="UTF-8"?>
<cinclude:cached-include src="cocoon:/items-list"
      xmlns:cinclude="http://apache.org/cocoon/include/1.0"/>

the cinclude transformer execute the call to the internal match ‘items-list’ only after 60 seconds from the first call, otherwise the result was taken from the cache.
The match ‘items-list’ could be whichever type of match, so you can have an non-heavy access to database if you don’t need to have a real-time data, or you can take a feed from another site without call it at every access.

Share