Interesting class Joerg. A couple of observations:
1) The remote site DO have Last-modified header and Cocoon is issuing a GET
request instead of a HEAD request
to obtain the header value. This is a common mistake made when using the
java.net.HttpURLConnection class. If you
want to make a HEAD request, you must use setRequestMethod("HEAD") on your
HttpURLConnection class before calling
the method to obtain the header value.
2) Regarding your implementation, I found very promising the idea of
creating a subclassed HTMLGenerator that
enables us to control the cache timeout. I am kind of a newbie in cocoon
source code, so could you
provide me general guidelines on how could I create a external sitemap
parameter to manage this time interval? It would
replace the hard coded value "10000" in your code.
Thanks in advance,
Gustavo
-----Mensagem original-----
De: Joerg Heinicke [mailto:[EMAIL PROTECTED]
Enviada em: segunda-feira, 29 de marco de 2004 18:46
Para: [EMAIL PROTECTED]
Assunto: Re: Cache and HTMLGenerator
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]