cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joerg Heinicke <joerg.heini...@gmx.de>
Subject Re: Cache and HTMLGenerator
Date Mon, 29 Mar 2004 21:45:37 GMT
On 29.03.2004 01:59, Gustavo Nalle Fernandes wrote:

> Hi, I am using HTMLGenerator in order to obtain contents from remote sites.
> By using a network sniffer, I noticed the HTMLGenerator always makes a GET
> request to the remote site in order to
> obtain the content. Is it possible to cache this content? Like specifying a
> period of time so that within
> this period, the HTML Generator uses a cached version instead of keep making
> the same request all the time?
> This would improve drastically performance, no matter what type of generator
> is used.

A look into HTMLGenerator's source shows that it is cacheable, but 
delegates the caching to the Source implementation, in your case 
probably URLSource and this one is trying to read getLastModified() on 
the URLConnection. If you have control over the remote site you probably 
have to set a header there for lastmodified.

For a more clever handling like you described it above on Cocoon side 
you have to subclass HTMLGenerator and surround the URLSource with a 
DelayedRefreshSourceWrapper. The code might look like:

public class DelayedHTMLGenerator extends HTMLGenerator {

   public void setup(SourceResolver resolver, Map objectModel,
                     String src, Parameters par)
   throws ProcessingException, SAXException, IOException {
     super.setup(resolver, objectModel, src, par);
     this.inputSource =
            new DelayedRefreshSourceWrapper(this.inputSource,  10000);
   }
}

(not tested)

The rest should be inherited and is not needed to be implemented.

Joerg

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


Mime
View raw message