You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Romano Trampus <tr...@univ.trieste.it> on 2005/04/20 11:16:11 UTC
CachingPointProcessingPipeline problem
Hi,
I've spent a week on this problem, trying to debug
AbstractCachingProcessingPipeline, CachingPointProcessingPipeline and a few
other classes (cocoon 2.1.7, jdk 1.5, tomcat 5).
The problem is about caching-point. My situation is the following (it seems
the same described in the sitemap.xconf):
G --- (T1) --- (S)XML
|
+ --- (T2) --- (S)SVG
The generator G makes a lot of query on a db. T1 is a simple trasformer
(XSLT) and T2 is a XSLT trasformer that trasform the data in XML/SVG.
Because the SVG serializer takes a long to process the data I want the
output from the generator G to be cached AND the output of the two complete
pipeline to be cached.
OK, it does not run as I want. So I began debugging. First I made a
generator (called "mio", source code is at the end of this mail). My
generator does nothing but prints "generato" and the key and validity
values, just to understand what is going on.
In the sitemap I have:
....
<!-- define my new simple generator -->
<map:generator label="content" name="mio" src="mio"/>
....
Below in the pipeline section I use:
....
<map:match pattern="mio">
<map:act type="request">
<map:generate type="mio" src="{requestQuery}"
pipeline-hints="caching-point" />
</map:act>
</map:match>
....
And I use the default defined view of the sitemap:
<map:views>
<map:view from-label="content" name="xml">
<map:serialize type="xml" />
</map:view>
<map:view from-label="content" name="html">
<map:transform src="stylesheets/system/xml2html.xslt"/>
<map:serialize type="html"/>
</map:view>
</map:views>
My generator uses the source message as a key (stripping out the
"cocoon-view=...." substring).
Well, if I request
http://localhost:8080/sba/mio?cocoon-view=html&pippo=5
and
http://localhost:8080/sba/mio?cocoon-view=xml&pippo=5
The generator (the generate method in the generator) is invoked twice. It's
the same if I set autoCachingPoint to on or off.
Looking to the cocoon source I've found the method
connectCachingPipeline(Environment environment)
in class CachingPointProcessingPipeline. First I thought the problem was the
system didn't check if the generator is cached so I inserted a empty xslt
trasformer just after the generator (i.e. in the match section). But nothing
changed.
Where I'm wrong?
Thank's a lot,
Romano
This is the generator source I use:
---
import org.apache.cocoon.*;
import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.cocoon.generation.*;
import org.apache.cocoon.xml.AttributesImpl;
import org.apache.excalibur.source.SourceValidity;
import org.apache.excalibur.source.impl.validity.TimeStampValidity;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.Composable;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.Serializable;
public class mio extends AbstractGenerator implements Composable,
CacheableProcessingComponent {
public void generate() throws SAXException, IOException,
ProcessingException {
String message=this.source;
String[] previousSearch=null;
String c="";
System.out.println("generato");
contentHandler.startDocument();
contentHandler.startElement("","root","root",new AttributesImpl());
contentHandler.startElement("","query","query",new
AttributesImpl());
contentHandler.characters(message.toCharArray(), 0,
message.length());
contentHandler.endElement("","query","query");
contentHandler.endElement("","root","root");
contentHandler.endDocument();
}
public void compose(ComponentManager manager) throws ComponentException
{
}
public Serializable getKey() {
String message=this.source;
if(message==null)return null;
if(message.startsWith("?cocoon-view=")) {
try {message="?"+message.substring(message.indexOf("&"));}
catch (Exception e) {}
}
System.out.println("getKey: "+message);
return message;
}
public SourceValidity getValidity() {
long t=System.currentTimeMillis()/1000000;
System.out.println("getValidity: "+t);
System.out.println("------------------");
if(t>0) {return new TimeStampValidity(t);}
else {return null;}
}
}
Re: CachingPointProcessingPipeline problem
Posted by tr...@univ.trieste.it.
Hi Bertrand,
> but did you look at the
> "cacheable" sample of the XSP block?
yes, it seems not to do more than I do in my generator (i.e. setting the
getKey and getValidity methods.
The only way I have found to have cache working is to set the transformers
as "non-cacheable". But this makes cocoon to cache only the generator (or up
to the first non-cacheable transformer) and nothing else. For this reason I
have to use the "caching-point" feature (I have to cache the complete response
and the generator both).
Debugging I've seen the parameter I've set is read and the object has the
correct value after the parameters parsing. I also know that two results are
stored in the cache, one for the complete response and one (I guess) for the
partial result at the point marked by the parameter.
But when the second request (with a different view) is received, cocoon first
check for a result matching the key of the complete response (keys are build
as a list of the key from the generator to the serializer) and of course it
doesn't find it.
Then it removes the keys from the list up to the "caching-point" and then it
should check again for a match in the cache and (I guess) if there is one
connect the pipeline between the correct producer/consumer pair. Well, this
second check seems to fail and I don't understand way.
All the joke is made in four java classes but methods are called ina fashion
that it's not very easy to understand (...ok, I'm not a cocoon guru :-) ).
I'll try to debug it again. I need that because we are developing an
opensource opac.
bye,
romano
Re: CachingPointProcessingPipeline problem
Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Romano,
I haven't looked at your code in depth, but did you look at the
"cacheable" sample of the XSP block?
It might give you useful additional information about how to get
caching to work.
-Bertrand