cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leszek Gawron <>
Subject Re: JXTG and caching - IT'S DONE
Date Thu, 03 Jun 2004 14:48:32 GMT
Upayavira wrote:
>>> It seems to me that Sylvains suggested extension of jxt has a great 
>>> deal of power in it.
>> OK. Then I'll continue my work and try to provide the appropriate 
>> patch as I have already started to make needed changes.
> Great. I'd love to see a cacheable jxt.
> Regards, Upayavira
You can test the first implementation if you fetch this file :

it contains : which you should put to the same directory as and rebuild your cocoon.

There also is a simple test case in test directory. Put it into your webapp 
root and then issue this url:

if I got it right the view is generated once for each key and cached so the 
date on the page won't change if you refresh your page.

How it works:

1. every attribute in "" namespace 
get stripped from attributes and end up in StartDocument event in 
templateProperties map (which I added). This is something that could be used 
for providing additional parameters to template in the future.
These attributes are not generated to output. They are only stored in map. 
This was the simplest solution. I think it's acceptable. How about you?

2. In template's root element (or any element really) you put:
<page jx:cache-key="${biz.getKey()}" jx:cache-validity=${biz.getValidity()}">
The key should be Serializable and the Validity should be SourceValidity of 

Voilla .. the page gets cached.

What changed:

1. CachingJXTemplateGenerator implements CacheableProcessingComponent
    of course :)
2. StartDocument.templateProperties added
3. I had to move template parsing from generate to setup(). Otherwise that 

- fetch http://localhost:8888/test/
- setup() called
- getKey() called - template not parsed yet, cannot compute key - no view
   caching will be done
- generate() - template gets parsed and generated, template cached
- refresh browser
- setup() called
- getKey() - got parsed template, can evaluate cache-key
- lookup from cache fails as the first response was not cached
- generate() - template already parsed
- response cached, getValidity() called somewhere of course

The response gets cached after second page hit because getKey() first time is 
called before template is parsed. When parsing is moved to setup() this happens:

- fetch http://localhost:8888/test/
- setup() called, template gets parsed
- getKey() called, template accessible, key computed
- cache lookup falils
- generate() called
- response cached!

This class can become standard JXTemplateGenerator as if you do not provide 
caching attributes the page never gets cached so it works like it did before.

Please make your comments

Leszek Gawron                            

View raw message