You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Jonathan Fuerth <fu...@sqlpower.ca> on 2001/02/16 00:55:54 UTC

cache difficulty

Good <util:time-of-day/>!

I searched the list archives for an answer to this one, but I fear my
problem may be unique.

I can't seem to get my xsp's final rendered output to cache.  I've
reduced the touble to the smallest useful amount of code I could.
Here it is:

----BEGIN cachetest.xml
cachetest.xml
<?xml version="1.0"?>
<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="general.xsl" type="text/xsl"?>

<xsp:page language="java" xmlns:util="http://www.apache.org/1999/XSP/Util" xmlns:xsp="http://www.apache.org/1999/XSP/Core">

<xsp:structure>
  <util:cacheable/>
  <xsp:include>java.text.*</xsp:include>
</xsp:structure>

<xsp:logic>
  public boolean hasChanged (Object context) {
    // return true here if the page content might have changed, or
    // false if it is safe to use a cached copy.
    return false;
  }
</xsp:logic>

<page>
        <xsp:logic>
                DateFormat df=new SimpleDateFormat("hh:mm:ss.SSS aa");
                String theTime=df.format(new java.util.Date());
        </xsp:logic>
        <para>Hello, the time is <xsp:expr>theTime</xsp:expr>.</para>
</page>

</xsp:page>
----END cachetest.xml

The xsl is of no consequence, so I won't paste it here.

So what I was doing to test was just request the page over and over
by pressing the reload button on my broswer.  I invariably got the
correct time and date, never a cached copy.

Then I thought, maybe the browser is sending a No-cache header in the
request!  I decided to use the world's most flexible web browser,
telnet(1).  Here's a transcript:

----BEGIN transcript
fenchurch% telnet majikthise 8080
Trying 192.168.0.114...
Connected to majikthise.sqlpower.ca.
Escape character is '^]'.
GET /scratch/cachetest.xml HTTP/1.1
Host: fenchurch:8080
User-Agent: cow
Accept: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */*
Accept-Language: en
Connection: Close

HTTP/1.0 200 OK
Content-Type: text/html
Content-Length: 262
Servlet-Engine: Tomcat Web Server/3.2.1 (JSP 1.1; Servlet 2.2; Java 1.3.0; Windows NT 4.0 x86; java.vendor=Sun Microsystems Inc.)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><title></title></head><body>

        <p>Hello, the time is 06:43:25.267 PM.</p>
</body></html>
<!-- This page was served in 110 milliseconds by Cocoon 1.8.2 -->Connection closed by foreign host.
fenchurch% telnet majikthise 8080
Trying 192.168.0.114...
Connected to majikthise.sqlpower.ca.
Escape character is '^]'.
GET /scratch/cachetest.xml HTTP/1.1
Host: fenchurch:8080
User-Agent: cow
Accept: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */*
Accept-Language: en
Connection: Close

HTTP/1.0 200 OK
[...]
        <p>Hello, the time is 06:43:42.552 PM.</p>
[...]
----END transcript

The requests are identical, so I seem to have ruled out the user-agent
as a problem.  That leaves my cocoon setup as the culprit.

My current version number and setup info are all in the http response
headers above, so I won't re-iterate and just introduce possible
typos. :-)

Thanks for any insights you may be able to share.

Jonathan Fuerth

Re: cache difficulty

Posted by Jonathan Fuerth <fu...@sqlpower.ca>.
First off, I'd like to thank everyone involved in providing cocoon to
the community, and for fulfilling the inevitable support demands it
generates!  I enjoy using cocoon for web development, and I truly
appreciate your collective hard work!

On Fri, Feb 16, 2001 at 12:42:38AM +0000, Sergio Carvalho wrote:
>  From a very diagonal reading of your e-mail, I'd say you misunderstood 
> the <util:cacheable/>'s objective. Tagging an XSP page with 
> util:cacheable won't cause Cocoon to emit HTTP/1.1 caching headers. It 
> will just make Cocoon's internal caching system to store the page on 
> cache, and if, when requested, it's not dirty (as per hasChanged()), 
> Cocoon retrieves the result from store, not by execution of the XSP page.

This is, in fact, the behaviour I want.  All the talk about headers
was just to demonstrate that I ruled out any http monkey-business.  I
do want what you just described.

To clarify my original post: I expect that the following code will
force cocoon to serve cached html on repeated requests from the same
user agent:

> > <xsp:logic>
> >   public boolean hasChanged (Object context) {
> >     // return true here if the page content might have changed, or
> >     // false if it is safe to use a cached copy.
> >     return false;
> >   }
> > </xsp:logic>

This is how I made sure the browser wasn't doing anything funny in the
request:

> > fenchurch% telnet majikthise 8080
> > Trying 192.168.0.114...
> > Connected to majikthise.sqlpower.ca.
> > Escape character is '^]'.
> > GET /scratch/cachetest.xml HTTP/1.1
> > Host: fenchurch:8080
> > User-Agent: cow
> > Accept: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */*
> > Accept-Language: en
> > Connection: Close
[...response headers snipped...]
> >         <p>Hello, the time is 06:43:25.267 PM.</p>

And on the next request with identical headers, the page contained
this, demonstrating that it was not in fact serving a cached copy of
the document:

> >         <p>Hello, the time is 06:43:42.552 PM.</p>

Sorry if my original post was misleading, and thanks again for the
speedy reply.

Jonathan Fuerth

Re: cache difficulty

Posted by Sergio Carvalho <sc...@criticalsoftware.com>.
 From a very diagonal reading of your e-mail, I'd say you misunderstood 
the <util:cacheable/>'s objective. Tagging an XSP page with 
util:cacheable won't cause Cocoon to emit HTTP/1.1 caching headers. It 
will just make Cocoon's internal caching system to store the page on 
cache, and if, when requested, it's not dirty (as per hasChanged()), 
Cocoon retrieves the result from store, not by execution of the XSP page.

If what you want is HTTP caching, such that web proxies will store your 
page, you'll need to emit the HTTP headers yourself explicitely. I don't 
know wether there is some taglib for this.



Jonathan Fuerth wrote:

> Good <util:time-of-day/>!
> 
> I searched the list archives for an answer to this one, but I fear my
> problem may be unique.
> 
> I can't seem to get my xsp's final rendered output to cache.  I've
> reduced the touble to the smallest useful amount of code I could.
> Here it is:
> 
> ----BEGIN cachetest.xml
> cachetest.xml
> <?xml version="1.0"?>
> <?cocoon-process type="xsp"?>
> <?cocoon-process type="xslt"?>
> <?xml-stylesheet href="general.xsl" type="text/xsl"?>
> 
> <xsp:page language="java" xmlns:util="http://www.apache.org/1999/XSP/Util" xmlns:xsp="http://www.apache.org/1999/XSP/Core">
> 
> <xsp:structure>
>   <util:cacheable/>
>   <xsp:include>java.text.*</xsp:include>
> </xsp:structure>
> 
> <xsp:logic>
>   public boolean hasChanged (Object context) {
>     // return true here if the page content might have changed, or
>     // false if it is safe to use a cached copy.
>     return false;
>   }
> </xsp:logic>
> 
> <page>
>         <xsp:logic>
>                 DateFormat df=new SimpleDateFormat("hh:mm:ss.SSS aa");
>                 String theTime=df.format(new java.util.Date());
>         </xsp:logic>
>         <para>Hello, the time is <xsp:expr>theTime</xsp:expr>.</para>
> </page>
> 
> </xsp:page>
> ----END cachetest.xml
> 
> The xsl is of no consequence, so I won't paste it here.
> 
> So what I was doing to test was just request the page over and over
> by pressing the reload button on my broswer.  I invariably got the
> correct time and date, never a cached copy.
> 
> Then I thought, maybe the browser is sending a No-cache header in the
> request!  I decided to use the world's most flexible web browser,
> telnet(1).  Here's a transcript:
> 
> ----BEGIN transcript
> fenchurch% telnet majikthise 8080
> Trying 192.168.0.114...
> Connected to majikthise.sqlpower.ca.
> Escape character is '^]'.
> GET /scratch/cachetest.xml HTTP/1.1
> Host: fenchurch:8080
> User-Agent: cow
> Accept: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */*
> Accept-Language: en
> Connection: Close
> 
> HTTP/1.0 200 OK
> Content-Type: text/html
> Content-Length: 262
> Servlet-Engine: Tomcat Web Server/3.2.1 (JSP 1.1; Servlet 2.2; Java 1.3.0; Windows NT 4.0 x86; java.vendor=Sun Microsystems Inc.)
> 
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
> <html><head><title></title></head><body>
> 
>         <p>Hello, the time is 06:43:25.267 PM.</p>
> </body></html>
> <!-- This page was served in 110 milliseconds by Cocoon 1.8.2 -->Connection closed by foreign host.
> fenchurch% telnet majikthise 8080
> Trying 192.168.0.114...
> Connected to majikthise.sqlpower.ca.
> Escape character is '^]'.
> GET /scratch/cachetest.xml HTTP/1.1
> Host: fenchurch:8080
> User-Agent: cow
> Accept: text/html, image/png, image/jpeg, image/gif, image/x-xbitmap, */*
> Accept-Language: en
> Connection: Close
> 
> HTTP/1.0 200 OK
> [...]
>         <p>Hello, the time is 06:43:42.552 PM.</p>
> [...]
> ----END transcript
> 
> The requests are identical, so I seem to have ruled out the user-agent
> as a problem.  That leaves my cocoon setup as the culprit.
> 
> My current version number and setup info are all in the http response
> headers above, so I won't re-iterate and just introduce possible
> typos. :-)
> 
> Thanks for any insights you may be able to share.
> 
> Jonathan Fuerth
> 
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
> 
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>
> 
> 
> 
>