Hi Ard,

it might be a good idea to post your knowledge about caching JXtemplate to the cocoon wiki so that other people can find it there instead of on the mailinglist.

WDYT?

Regards,

Reijn

Ard Schrijvers wrote:
Again, and now really in a new thread...!

"I am not familiar with xsp (anymore). I use jx all the time (with flow). It is by default not cached, though you can arrange this via flow.
How do you do this (cache) in flow?"


I have changed the name of this thread since this part drifts away from the 
inital subject. Probably known by lots of users of jx is that the 
org.apache.cocoon.generation.JXTemplateGenerator by default is not cacheable. 
This is because lots of logic the components setup is not aware of might be 
present in the the file that is generated by the JXTemplateGenerator (the setup 
of a component must be able to return the cachekey that is processed in the 
pipeline cachekey AND the validity). Suppose you are doing some date functions 
in your jx, computing the current week. This can never be cached because the 
pipeline key or validity has no dependence on what happens during the 
generation of the jx file.

But, since we often know where our specific jx depends on, you can make it being cached.
So, when you are in your flow function you define your cachekey for the jx, and 
the valdity type:

var ck='KEY-';
var params={'cacheValidity': NOPValidity.SHARED_INSTANCE};
// NOPValidity merely means something like: assume I am always valid. You can 
equally well define an expires validity if it is only valid for some time, or 
an eventValidity, or a timeStampValdity or...that is about it I think

now, to var ck you append the things that is depends on (like a request 
parameter, current week number, etc)

you add it to params:

params['ck']=ck;

and go back to the sitemap with
cocoon.sendPage(foo, params);

You have the matcher
<map:match pattern="foo">
        <map:generate type="jx" src="bar.xml">

and bar.xml starts with:

<some-element jx:cache-key="${ck}" jx:cache-validity="${cacheValidity}"

Now, your JXTemplateGenerator is cached.
Since we had to repeat this pattern many many times (sitemap --> flow --> sitemap 
--> jx ) we have extended the JXTemplateGenerator, where you can very easily make 
your jx cacheable. (you just generate it, and everything it depends on is added to it 
with map:parameter)...

So for example, I have a jx depending on session and date and request-param, 
then

<map:generate src="bar.xml" type="jx" >
        <map:parameter name="foo" value="{session-attr:name}"/>
<map:parameter name="path" value="{request-param:path}"/> <map:parameter name="depth" value="{date:yyyyMMdd}"/>
</map:generate>

Now, the cached jx would depend on these three parameters. Very easy to use, and less error prone than the flow part. If somebody is interested in the code I will hear
ps it is not written by me so it might be in cocoon trunk already but I dont 
think so

Regards Ard


--
Met vriendelijke groet,
Kind regards,

Jeroen Reijn

Hippo

Oosteinde 11
1017WT Amsterdam
The Netherlands
Tel  +31 (0)20 5224466


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to