You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Hans-Guenter Stein <Ha...@siteos.de> on 2001/04/10 14:32:54 UTC

cacheable: why is it not working?

Any hint on this:

My pages never cache. The code looks like:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
 <xsp:page language="java"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xsp="http://www.apache.org/1999/XSP/Core"
  xmlns:util="http://www.apache.org/1999/XSP/Util"
 >
 <xsp:structure>
  <util:cacheable/>
 </xsp:structure>
 <xsp:logic>
  public boolean hasChanged (Object context)
  {
   ErrorLog.print("cached");
   return false;
  }
 </xsp:logic>
 <roottag>
  <xsp:logic>
    ErrorLog.print("not cached");
    <xsp:pi target="xml-stylesheet">href="xsl/nothing.xsl"
type="text/xsl"</xsp:pi>
  </xsp:logic>
 </roottag>
</xsp:page>

In the resulting java-source in the cocoon-repository, there is no hint
on the isCachable-method:
(WHAT SHOULD IT LOOK LIKE, IF THE ISCACHABLE-METHOD IS IN THE CODE???)

    package _projects._Entwicklung._apache8000._siteos._www._htdocs;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import org.apache.cocoon.parser.*;
    import org.apache.cocoon.producer.*;
    import org.apache.cocoon.framework.*;
    import org.apache.cocoon.processor.xsp.*;
    import org.apache.cocoon.processor.xsp.library.*;
    /* User Imports */
      import java.net.URL;
      import java.util.Date;
      import java.text.SimpleDateFormat;
    public class _cachetest extends XSPPage {
      /* User Class Declarations */
  public boolean hasChanged (Object context)
  {
   myCode.ErrorLog.print("cached");
   return false;
  }
      public void populateDocument(
        HttpServletRequest request,
        HttpServletResponse response,
        Document document
      )
        throws Exception
      {
        // Node stack logic variables
        Node xspParentNode = null;
        Node xspCurrentNode = document;
        Stack xspNodeStack = new Stack();
        // Make session object readily available
        HttpSession session = request.getSession(false);
          document.appendChild(
            document.createProcessingInstruction(
              "cocoon-process",
              "type=\"xslt\""
            )
          );
    xspParentNode = xspCurrentNode;
    xspNodeStack.push(xspParentNode);
    xspCurrentNode =
      document.createElement("roottag");
    xspParentNode.appendChild(xspCurrentNode);
      ((Element) xspCurrentNode).setAttribute(
        "xmlns:xsl",
        "http://www.w3.org/1999/XSL/Transform"
      );
    xspCurrentNode.appendChild(
      document.createTextNode("\n  ")
    );
    myCode.ErrorLog.print("not cached");
    document.insertBefore(
       document.createProcessingInstruction(
         "xml-stylesheet",
               "href=\"xsl/nothing.xsl\" type=\"text/xsl\""
         +
         ""
       ), document.getDocumentElement ()
     );
    xspCurrentNode.appendChild(
      document.createTextNode("\n ")
    );
    ((Element) xspCurrentNode).normalize();
    xspCurrentNode = (Node) xspNodeStack.pop();
      }
    }



---------------------------------------------------------------------
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>


RE: cacheable: why is it not working?

Posted by Donald Ball <ba...@webslingerZ.com>.
On Tue, 10 Apr 2001, Paul Nock wrote:

> In my case I found the xsp:structure/util:cacheable wasn't matching in the
> util logicsheet as it should when I put
> <xsp:structure>
>         <util:cacheable/>
> </xsp:structure>
> under an <xsp:page> tag as documented in my XSP page.
>
> I got it working by brute-force, adding an explicit <apply-templates> for it
> in the util logicsheet, and also adding the hasChanged code to the
> util:cacheable template.  No idea if this was a good solution, but it did
> seemed to cache the page.

pragmatically, i just manually create a public boolean isChangeable() {
return true; } method myself and have done with it.

- donald


---------------------------------------------------------------------
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>


RE: cacheable: why is it not working?

Posted by Paul Nock <pn...@medicineplanet.com>.
In my case I found the xsp:structure/util:cacheable wasn't matching in the
util logicsheet as it should when I put
<xsp:structure>
        <util:cacheable/>
</xsp:structure>
under an <xsp:page> tag as documented in my XSP page.

I got it working by brute-force, adding an explicit <apply-templates> for it
in the util logicsheet, and also adding the hasChanged code to the
util:cacheable template.  No idea if this was a good solution, but it did
seemed to cache the page.

Here's my new part of the util.xsl stylesheet:

================================================
  <xsl:template match="xsp:page">
    <xsp:page>
      <xsl:apply-templates select="@*"/>

      <xsp:structure>
        <xsp:include>java.net.URL</xsp:include>
        <xsp:include>java.util.Date</xsp:include>
        <xsp:include>java.text.SimpleDateFormat</xsp:include>
      </xsp:structure>

***** added this ****     <xsl:apply-templates
select="xsp:structure/util:cacheable"/> ****
      <xsl:apply-templates/>
    </xsp:page>
  </xsl:template>

  <!-- Mark page as cacheable -->
  <xsl:template match="xsp:structure/util:cacheable">
    <xsp:logic>
      public boolean isCacheable (HttpServletRequest request) {
        return true;
      }

     static long last_changed_millis = 0;
     static final long MILLISECONDS_TO_CACHE = 5*60*1000;

     public boolean hasChanged(Object context) {
       long current_millis = System.currentTimeMillis();
       if (current_millis - MILLISECONDS_TO_CACHE &gt; last_changed_millis)
{
         last_changed_millis = current_millis;
         return true;
       } else {
         return false;
       }
     }
    </xsp:logic>
  </xsl:template>
....

Paul

-----Original Message-----
From: Hans-Guenter Stein [mailto:Hans-Guenter.Stein@siteos.de]
Sent: Tuesday, April 10, 2001 5:33 AM
To: cocoon-users@xml.apache.org
Subject: cacheable: why is it not working?


Any hint on this:

My pages never cache. The code looks like:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
 <xsp:page language="java"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xsp="http://www.apache.org/1999/XSP/Core"
  xmlns:util="http://www.apache.org/1999/XSP/Util"
 >
 <xsp:structure>
  <util:cacheable/>
 </xsp:structure>
 <xsp:logic>
  public boolean hasChanged (Object context)
  {
   ErrorLog.print("cached");
   return false;
  }
 </xsp:logic>
 <roottag>
  <xsp:logic>
    ErrorLog.print("not cached");
    <xsp:pi target="xml-stylesheet">href="xsl/nothing.xsl"
type="text/xsl"</xsp:pi>
  </xsp:logic>
 </roottag>
</xsp:page>

In the resulting java-source in the cocoon-repository, there is no hint
on the isCachable-method:
(WHAT SHOULD IT LOOK LIKE, IF THE ISCACHABLE-METHOD IS IN THE CODE???)

    package _projects._Entwicklung._apache8000._siteos._www._htdocs;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import org.apache.cocoon.parser.*;
    import org.apache.cocoon.producer.*;
    import org.apache.cocoon.framework.*;
    import org.apache.cocoon.processor.xsp.*;
    import org.apache.cocoon.processor.xsp.library.*;
    /* User Imports */
      import java.net.URL;
      import java.util.Date;
      import java.text.SimpleDateFormat;
    public class _cachetest extends XSPPage {
      /* User Class Declarations */
  public boolean hasChanged (Object context)
  {
   myCode.ErrorLog.print("cached");
   return false;
  }
      public void populateDocument(
        HttpServletRequest request,
        HttpServletResponse response,
        Document document
      )
        throws Exception
      {
        // Node stack logic variables
        Node xspParentNode = null;
        Node xspCurrentNode = document;
        Stack xspNodeStack = new Stack();
        // Make session object readily available
        HttpSession session = request.getSession(false);
          document.appendChild(
            document.createProcessingInstruction(
              "cocoon-process",
              "type=\"xslt\""
            )
          );
    xspParentNode = xspCurrentNode;
    xspNodeStack.push(xspParentNode);
    xspCurrentNode =
      document.createElement("roottag");
    xspParentNode.appendChild(xspCurrentNode);
      ((Element) xspCurrentNode).setAttribute(
        "xmlns:xsl",
        "http://www.w3.org/1999/XSL/Transform"
      );
    xspCurrentNode.appendChild(
      document.createTextNode("\n  ")
    );
    myCode.ErrorLog.print("not cached");
    document.insertBefore(
       document.createProcessingInstruction(
         "xml-stylesheet",
               "href=\"xsl/nothing.xsl\" type=\"text/xsl\""
         +
         ""
       ), document.getDocumentElement ()
     );
    xspCurrentNode.appendChild(
      document.createTextNode("\n ")
    );
    ((Element) xspCurrentNode).normalize();
    xspCurrentNode = (Node) xspNodeStack.pop();
      }
    }



---------------------------------------------------------------------
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>


---------------------------------------------------------------------
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>