You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Kris Rasmussen <kr...@yahoo.com> on 2005/02/11 01:42:36 UTC

Extract Content From IMarkupWriter?

Is it possible to extract the content in a String from a IMarkupWriter for purposes of component level caching? I am creating a cms system and I would like to be able to cache the final rendering of a component. In order to do this on a component level I need to be able to read what has been renderered to a IMarkupWriter.
 
Thanks,
Kris

		
---------------------------------
Do you Yahoo!?
 Yahoo! Mail - Helps protect you from nasty viruses.

Re: Extract Content From IMarkupWriter?

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
It would be handy if there were OSCache Tapestry components similar to 
the Taglibs:

	http://www.opensymphony.com/oscache/wiki/JSP%20Tags.html


On Feb 11, 2005, at 10:55 AM, Danny Mandel wrote:

> I did a similar thing but wasn't able to correctly piggy back things 
> (I gave up after 2 hrs or so).  I ended up calling render component 
> twice and the second time storing the content in my cache.  It worked 
> well enough for me since the number of cache accesses greatly 
> outnumber the number of non cache accesses.
>
> The relevant portions of the code are as follows:
>
>    public void prepareForRender(IRequestCycle cycle) {
>        super.prepareForRender(cycle);
>        String results = getCachedOutput();
>        setOutput(results);
>        Boolean useCache = (Boolean) 
> cycle.getAttribute(CacheAndPublicAwarePage.USE_CACHE);
>        if (useCache != null && useCache.booleanValue()) {
>            setUseCache(true);
>        } else {
>            setUseCache(false);
>        }
>    }
>      protected void renderComponent(IMarkupWriter writer, 
> IRequestCycle cycle) {
>        String results = getOutput();              
> super.renderComponent(writer, cycle);
>        if (results == null) {
>            ByteArrayOutputStream stream = new 
> ByteArrayOutputStream(2000);
>            HTMLWriter otherWriter = new HTMLWriter(stream);
>            super.renderComponent(otherWriter, cycle);
>            otherWriter.flush();
>            if (getUseCache()) {
>                setCachedOutput(stream.toString());
>            }
>        }
>    }
>
> If you get it working, let me know, as I'll happily replace my flawed 
> version.  :)
>
> Danny
>
> Kris Rasmussen wrote:
>
>> I just took a look at the NestedHTMLWriter and noticed that if I were 
>> to create a similar class with a getter to return the CharArrayWriter 
>> then I should be able to do what I need. If someone has experience 
>> with this and has any suggestions please let me know. I am creating a 
>> wrapper component that checks a cache before rendering its body. If 
>> the cache contains the content it needs then it just prints out the 
>> cache, otherwise it renders its body and stores the result back in 
>> the cache.
>> Thanks,
>> Kris
>>
>> Kris Rasmussen <kr...@yahoo.com> wrote:
>> Is it possible to extract the content in a String from a 
>> IMarkupWriter for purposes of component level caching? I am creating 
>> a cms system and I would like to be able to cache the final rendering 
>> of a component. In order to do this on a component level I need to be 
>> able to read what has been renderered to a IMarkupWriter.
>>
>> Thanks,
>> Kris
>>
>>
>> ---------------------------------
>> Do you Yahoo!?
>> Yahoo! Mail - Helps protect you from nasty viruses.
>> 		
>> ---------------------------------
>> Do you Yahoo!?
>> Yahoo! Search presents - Jib Jab's 'Second Term'
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Extract Content From IMarkupWriter?

Posted by Kris Rasmussen <kr...@yahoo.com>.
Got you. The way I am doing it is actually to create a completetly new component called a CachingRenderBlock. This will cache its block unless the block tells it not too.
 
Kris

Danny Mandel <dm...@tolweb.org> wrote:
I think that I did this when I was first learning Tapestry and so every 
component that had this caching behavior has a conditional tag in the 
html. I.E.




invert="ognl:true">
.....


Clearly this isn't the best way to do it, but it works.

Danny

Kris Rasmussen wrote:

>Thanks, nice to see others are doing the same thing. When I get to implementing this I will let you know what I do to avoid calling render component twice. I may not be getting something, but I don't see where you are ever outputing your cache to a writer? I see that you insert the rendered component into cache when the getOuput function returns null but above that it looks like you are just rendering the component as usual and never actually using the cached version.
> 
>Kris
>
>Danny Mandel wrote:
>I did a similar thing but wasn't able to correctly piggy back things (I 
>gave up after 2 hrs or so). I ended up calling render component twice 
>and the second time storing the content in my cache. It worked well 
>enough for me since the number of cache accesses greatly outnumber the 
>number of non cache accesses.
>
>The relevant portions of the code are as follows:
>
>public void prepareForRender(IRequestCycle cycle) {
>super.prepareForRender(cycle);
>String results = getCachedOutput();
>setOutput(results);
>Boolean useCache = (Boolean) 
>cycle.getAttribute(CacheAndPublicAwarePage.USE_CACHE);
>if (useCache != null && useCache.booleanValue()) {
>setUseCache(true);
>} else {
>setUseCache(false);
>}
>}
>
>protected void renderComponent(IMarkupWriter writer, IRequestCycle 
>cycle) {
>String results = getOutput(); 
>super.renderComponent(writer, cycle);
>if (results == null) {
>ByteArrayOutputStream stream = new ByteArrayOutputStream(2000);
>HTMLWriter otherWriter = new HTMLWriter(stream);
>super.renderComponent(otherWriter, cycle);
>otherWriter.flush();
>if (getUseCache()) {
>setCachedOutput(stream.toString());
>}
>}
>}
>
>If you get it working, let me know, as I'll happily replace my flawed 
>version. :)
>
>Danny
>
>Kris Rasmussen wrote:
>
> 
>
>>I just took a look at the NestedHTMLWriter and noticed that if I were to create a similar class with a getter to return the CharArrayWriter then I should be able to do what I need. If someone has experience with this and has any suggestions please let me know. I am creating a wrapper component that checks a cache before rendering its body. If the cache contains the content it needs then it just prints out the cache, otherwise it renders its body and stores the result back in the cache.
>>
>>Thanks,
>>Kris
>>
>>Kris Rasmussen wrote:
>>Is it possible to extract the content in a String from a IMarkupWriter for purposes of component level caching? I am creating a cms system and I would like to be able to cache the final rendering of a component. In order to do this on a component level I need to be able to read what has been renderered to a IMarkupWriter.
>>
>>Thanks,
>>Kris
>>
>>
>>---------------------------------
>>Do you Yahoo!?
>>Yahoo! Mail - Helps protect you from nasty viruses.
>>
>>---------------------------------
>>Do you Yahoo!?
>>Yahoo! Search presents - Jib Jab's 'Second Term'
>>
>>
>> 
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>__________________________________________________
>Do You Yahoo!?
>Tired of spam? Yahoo! Mail has the best spam protection around 
>http://mail.yahoo.com 
> 
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


		
---------------------------------
Do you Yahoo!?
 Yahoo! Search presents - Jib Jab's 'Second Term'

Re: Extract Content From IMarkupWriter?

Posted by Danny Mandel <dm...@tolweb.org>.
I think that I did this when I was first learning Tapestry and so every 
component that had this caching behavior has a conditional tag in the 
html.  I.E.

<span jwcid="@Conditional" condition="ognl:useCache && output != null">
    <span jwcid="@Insert" value="ognl:output" raw="ognl:true"/>
</span>
<span jwcid="@Conditional" condition="ognl:useCache && output != null" 
invert="ognl:true">
.....
</span>

Clearly this isn't the best way to do it, but it works.

Danny

Kris Rasmussen wrote:

>Thanks, nice to see others are doing the same thing. When I get to implementing this I will let you know what I do to avoid calling render component twice. I may not be getting something, but I don't see where you are ever outputing your cache to a writer? I see that you insert the rendered component into cache when the getOuput function returns null but above that it looks like you are just rendering the component as usual and never actually using the cached version.
> 
>Kris
>
>Danny Mandel <dm...@tolweb.org> wrote:
>I did a similar thing but wasn't able to correctly piggy back things (I 
>gave up after 2 hrs or so). I ended up calling render component twice 
>and the second time storing the content in my cache. It worked well 
>enough for me since the number of cache accesses greatly outnumber the 
>number of non cache accesses.
>
>The relevant portions of the code are as follows:
>
>public void prepareForRender(IRequestCycle cycle) {
>super.prepareForRender(cycle);
>String results = getCachedOutput();
>setOutput(results);
>Boolean useCache = (Boolean) 
>cycle.getAttribute(CacheAndPublicAwarePage.USE_CACHE);
>if (useCache != null && useCache.booleanValue()) {
>setUseCache(true);
>} else {
>setUseCache(false);
>}
>}
>
>protected void renderComponent(IMarkupWriter writer, IRequestCycle 
>cycle) {
>String results = getOutput(); 
>super.renderComponent(writer, cycle);
>if (results == null) {
>ByteArrayOutputStream stream = new ByteArrayOutputStream(2000);
>HTMLWriter otherWriter = new HTMLWriter(stream);
>super.renderComponent(otherWriter, cycle);
>otherWriter.flush();
>if (getUseCache()) {
>setCachedOutput(stream.toString());
>}
>}
>}
>
>If you get it working, let me know, as I'll happily replace my flawed 
>version. :)
>
>Danny
>
>Kris Rasmussen wrote:
>
>  
>
>>I just took a look at the NestedHTMLWriter and noticed that if I were to create a similar class with a getter to return the CharArrayWriter then I should be able to do what I need. If someone has experience with this and has any suggestions please let me know. I am creating a wrapper component that checks a cache before rendering its body. If the cache contains the content it needs then it just prints out the cache, otherwise it renders its body and stores the result back in the cache.
>>
>>Thanks,
>>Kris
>>
>>Kris Rasmussen wrote:
>>Is it possible to extract the content in a String from a IMarkupWriter for purposes of component level caching? I am creating a cms system and I would like to be able to cache the final rendering of a component. In order to do this on a component level I need to be able to read what has been renderered to a IMarkupWriter.
>>
>>Thanks,
>>Kris
>>
>>
>>---------------------------------
>>Do you Yahoo!?
>>Yahoo! Mail - Helps protect you from nasty viruses.
>>
>>---------------------------------
>>Do you Yahoo!?
>>Yahoo! Search presents - Jib Jab's 'Second Term'
>>
>>
>>    
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>__________________________________________________
>Do You Yahoo!?
>Tired of spam?  Yahoo! Mail has the best spam protection around 
>http://mail.yahoo.com 
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Extract Content From IMarkupWriter?

Posted by Kris Rasmussen <kr...@yahoo.com>.
Thanks, nice to see others are doing the same thing. When I get to implementing this I will let you know what I do to avoid calling render component twice. I may not be getting something, but I don't see where you are ever outputing your cache to a writer? I see that you insert the rendered component into cache when the getOuput function returns null but above that it looks like you are just rendering the component as usual and never actually using the cached version.
 
Kris

Danny Mandel <dm...@tolweb.org> wrote:
I did a similar thing but wasn't able to correctly piggy back things (I 
gave up after 2 hrs or so). I ended up calling render component twice 
and the second time storing the content in my cache. It worked well 
enough for me since the number of cache accesses greatly outnumber the 
number of non cache accesses.

The relevant portions of the code are as follows:

public void prepareForRender(IRequestCycle cycle) {
super.prepareForRender(cycle);
String results = getCachedOutput();
setOutput(results);
Boolean useCache = (Boolean) 
cycle.getAttribute(CacheAndPublicAwarePage.USE_CACHE);
if (useCache != null && useCache.booleanValue()) {
setUseCache(true);
} else {
setUseCache(false);
}
}

protected void renderComponent(IMarkupWriter writer, IRequestCycle 
cycle) {
String results = getOutput(); 
super.renderComponent(writer, cycle);
if (results == null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream(2000);
HTMLWriter otherWriter = new HTMLWriter(stream);
super.renderComponent(otherWriter, cycle);
otherWriter.flush();
if (getUseCache()) {
setCachedOutput(stream.toString());
}
}
}

If you get it working, let me know, as I'll happily replace my flawed 
version. :)

Danny

Kris Rasmussen wrote:

>I just took a look at the NestedHTMLWriter and noticed that if I were to create a similar class with a getter to return the CharArrayWriter then I should be able to do what I need. If someone has experience with this and has any suggestions please let me know. I am creating a wrapper component that checks a cache before rendering its body. If the cache contains the content it needs then it just prints out the cache, otherwise it renders its body and stores the result back in the cache.
> 
>Thanks,
>Kris
>
>Kris Rasmussen wrote:
>Is it possible to extract the content in a String from a IMarkupWriter for purposes of component level caching? I am creating a cms system and I would like to be able to cache the final rendering of a component. In order to do this on a component level I need to be able to read what has been renderered to a IMarkupWriter.
>
>Thanks,
>Kris
>
>
>---------------------------------
>Do you Yahoo!?
>Yahoo! Mail - Helps protect you from nasty viruses.
> 
>---------------------------------
>Do you Yahoo!?
> Yahoo! Search presents - Jib Jab's 'Second Term'
> 
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: Extract Content From IMarkupWriter?

Posted by Danny Mandel <dm...@tolweb.org>.
I did a similar thing but wasn't able to correctly piggy back things (I 
gave up after 2 hrs or so).  I ended up calling render component twice 
and the second time storing the content in my cache.  It worked well 
enough for me since the number of cache accesses greatly outnumber the 
number of non cache accesses.

The relevant portions of the code are as follows:

    public void prepareForRender(IRequestCycle cycle) {
        super.prepareForRender(cycle);
        String results = getCachedOutput();
        setOutput(results);
        Boolean useCache = (Boolean) 
cycle.getAttribute(CacheAndPublicAwarePage.USE_CACHE);
        if (useCache != null && useCache.booleanValue()) {
            setUseCache(true);
        } else {
            setUseCache(false);
        }
    }
   
    protected void renderComponent(IMarkupWriter writer, IRequestCycle 
cycle) {
        String results = getOutput();       
        super.renderComponent(writer, cycle);
        if (results == null) {
            ByteArrayOutputStream stream = new ByteArrayOutputStream(2000);
            HTMLWriter otherWriter = new HTMLWriter(stream);
            super.renderComponent(otherWriter, cycle);
            otherWriter.flush();
            if (getUseCache()) {
                setCachedOutput(stream.toString());
            }
        }
    }

If you get it working, let me know, as I'll happily replace my flawed 
version.  :)

Danny

Kris Rasmussen wrote:

>I just took a look at the NestedHTMLWriter and noticed that if I were to create a similar class with a getter to return the CharArrayWriter then I should be able to do what I need. If someone has experience with this and has any suggestions please let me know. I am creating a wrapper component that checks a cache before rendering its body. If the cache contains the content it needs then it just prints out the cache, otherwise it renders its body and stores the result back in the cache.
> 
>Thanks,
>Kris
>
>Kris Rasmussen <kr...@yahoo.com> wrote:
>Is it possible to extract the content in a String from a IMarkupWriter for purposes of component level caching? I am creating a cms system and I would like to be able to cache the final rendering of a component. In order to do this on a component level I need to be able to read what has been renderered to a IMarkupWriter.
>
>Thanks,
>Kris
>
>
>---------------------------------
>Do you Yahoo!?
>Yahoo! Mail - Helps protect you from nasty viruses.
>		
>---------------------------------
>Do you Yahoo!?
> Yahoo! Search presents - Jib Jab's 'Second Term'
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Extract Content From IMarkupWriter?

Posted by Kris Rasmussen <kr...@yahoo.com>.
I just took a look at the NestedHTMLWriter and noticed that if I were to create a similar class with a getter to return the CharArrayWriter then I should be able to do what I need. If someone has experience with this and has any suggestions please let me know. I am creating a wrapper component that checks a cache before rendering its body. If the cache contains the content it needs then it just prints out the cache, otherwise it renders its body and stores the result back in the cache.
 
Thanks,
Kris

Kris Rasmussen <kr...@yahoo.com> wrote:
Is it possible to extract the content in a String from a IMarkupWriter for purposes of component level caching? I am creating a cms system and I would like to be able to cache the final rendering of a component. In order to do this on a component level I need to be able to read what has been renderered to a IMarkupWriter.

Thanks,
Kris


---------------------------------
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
		
---------------------------------
Do you Yahoo!?
 Yahoo! Search presents - Jib Jab's 'Second Term'