You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Stephen Ng <st...@lumigent.com> on 2002/10/28 22:37:23 UTC

RE: CaheValidity & toString()

Okay, I think I've found the problem with my aggregate caching.

I have an xsp, and I use the cocoon:/ protocol to map:aggregate that xsp.  Something like the usual:

<map:match pattern="foo">
 <map:aggregate element="site">
  <map:part src="cocoon:/from-an-xsp.xml"/>
 </map:aggregate>
...

The symptom is that if I ask for 

http://foo?param=1

and then ask for that same url again, everything appears to be read from the cache.

But, if I ask for

http://foo?param=2

and then ask for  

http://foo?param=1

according the logs, Cocoon is re-aggregating the cached content of my xsp, rather than using the cached aggregated value.  (This is a problem because I have quite a few transformations that take place after that aggregation, and they all get re-run needlessly).

The problem appears to be that the aggregated content has a key which is based upon the src string (cocoon:/from-an-xsp.xml) which, in this case, is identical--it doesn't bother to ask the xsp for its key value.

A workaround for this is to make the ContentAggregator key based upon the source's getLastModified() number (which, at least, is based upon hash of xsp's validity object [SitemapSource:refresh()]).

In ContentAggregator:
    public long generateKey() {
		    // ...
                if (current.getLastModified() == 0) {
                        return 0;
                } else {
			  // ...
                    key += current.getLastModified();  // <-- ADD THIS LINE
                }
                // ...

Does the problem & solution make sense?  If so, should I submit a patch?

Thanks,

Steve

> -----Original Message-----
> From: Stephen Ng 
> Sent: Monday, October 28, 2002 10:42 AM
> To: cocoon-users@xml.apache.org; dlagardere@yahoo.fr
> Subject: RE: CaheValidity & toString()
> 
> 
> I am running into this same problem (I think) but I'm 
> confused as to what to do about it.
> 
> I have xsp's with generateKey() and 
> generateValidity()methods, and when I put the xsp in an 
> aggregate, cocoon re-aggregates every time, instead of used 
> the cached aggregated value.  The symptom is that it says 
> that the TimeStamp Validity is not the same for my aggregated 
> component.
> 
> I'm using my own CacheValidity, which does have a toString() method.
> 
> I've tried replacing my xsp with the cacheable.xsp from the 
> cocoon sample application, and I get the same problem--the 
> aggregate isn't cached.
> 
> Is there some other method I need to implement somewhere?
> 
> Thanks,
> 
> Steve
> 
> > -----Original Message-----
> > From: David LAGARDERE [mailto:dlagardere@yahoo.fr]
> > Sent: Friday, September 13, 2002 3:54 PM
> > To: cocoon-users@xml.apache.org
> > Subject: CaheValidity & toString()
> > 
> > 
> > Hello.
> > 
> > Sorry if the following was documented. However, after
> > many hours I spent on it, I found interesting to
> > describe what I've found about Caching.
> > 
> > I would like to have your opinion on a solution I've
> > found to my troubles with Cacheability of aggregated
> > content (see the previous mails I've sent).
> > 
> > The problem I had was the fact that Cocoon didn't
> > cache a StreamPipeline containing an aggregator
> > composed of my own Cacheable Generator : the log
> > told me the TimeStamp Validity of the Pipeline changed
> > everytime I requested the page whereas my generator was 
> always valid !
> > 
> > As each part of an aggregator is a SitemapSource
> > instance, the key and the validity of the pipeline are
> > built upon the SitemapSource last modification date.
> > This date is the concatenation of the Pipeline Cached
> > Key string value and the Pipeline Validity string
> > value.
> > The Pipeline Validity is a Map which associate a
> > Component Cached Key with its validty. Its string 
> > representation is the string representation of each pair 
> > {key, value}, that is , a call to the toString() method on 
> > both Component cached key and Component validity objects. 
> > As a consequence, every validity may overload the
> > toString() method returning a relevant value otherwise
> > the returned value will be the memory address of the
> > object, which of course, can't be taken as a relevant
> > value.
> > 
> > Please tell me if I'm wrong, but this is the only way
> > I've found to have my CachingStreamPipeline cached !
> > 
> > 
> > David Lagardere
> > 
> > 
> > ___________________________________________________________
> > Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en
> > français ! Yahoo! Mail : http://fr.mail.yahoo.com
> > 
> > 
> ---------------------------------------------------------------------
> > Please check that your question  has not already been 
> answered in the
> > FAQ before posting.     
> <http://xml.apache.org/cocoon/faq/index.html>
> > 
> > To 
> unsubscribe, e-mail:     <co...@xml.apache.org>
> > For additional commands, e-mail:   
> <co...@xml.apache.org>
> > 
> > 
> 
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
> 
> To unsubscribe, e-mail:     <co...@xml.apache.org>
> For additional commands, e-mail:   <co...@xml.apache.org>
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Re: CaheValidity & toString()

Posted by Vadim Gritsenko <va...@verizon.net>.
Stephen Ng wrote:

>Okay, I think I've found the problem with my aggregate caching.
>
>I have an xsp, and I use the cocoon:/ protocol to map:aggregate that xsp.  Something like the usual:
>
><map:match pattern="foo">
> <map:aggregate element="site">
>  <map:part src="cocoon:/from-an-xsp.xml"/>
> </map:aggregate>
>...
>
>The symptom is that if I ask for 
>
>http://foo?param=1
>
>and then ask for that same url again, everything appears to be read from the cache.
>
>But, if I ask for
>
>http://foo?param=2
>
>and then ask for  
>
>http://foo?param=1
>
>according the logs, Cocoon is re-aggregating the cached content of my xsp, rather than using the cached aggregated value. 
>

... which means that these two URLs produce different Validity objects 
in from-an-xsp pipeline. Is it right?


>(This is a problem because I have quite a few transformations that take place after that aggregation, and they all get re-run needlessly).
>
>The problem appears to be that the aggregated content has a key which is based upon the src string (cocoon:/from-an-xsp.xml) which, in this case, is identical--it doesn't bother to ask the xsp for its key value.
>

But what about validity? Seems that it changes.


>A workaround for this is to make the ContentAggregator key based upon the source's getLastModified() number (which, at least, is based upon hash of xsp's validity object [SitemapSource:refresh()]).
>
>In ContentAggregator:
>    public long generateKey() {
>		    // ...
>                if (current.getLastModified() == 0) {
>                        return 0;
>                } else {
>			  // ...
>                    key += current.getLastModified();  // <-- ADD THIS LINE
>

Right now it has:
                        key += HashUtil.hash("P=" +
                                         part.stripRootElement + ':' +
                                         current.getSystemId() + ';');

And that is correct.


>                }
>                // ...
>
>Does the problem & solution make sense?
>

No, it does not (yet) make sense to me. May be your explanation about 
validity of the aggregated pipeline will help.

Vadim

...



---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org