You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Michael Musson <mu...@gmail.com> on 2005/04/24 22:50:54 UTC

Cache control results?

I have a control that must do some intensive calls in order to render
itself. The actual content of the control will normally render
unchanged from call to call. There are only a few well defined spots
that could change the content of the control.

Ideally I would like to have the control save a copy of its output and
return this on renders until I call a method to clear the cache in
which case the control would redo the calls necessary to render
itself.

Is there a way to do caching like this directly in Tapestry or do you
have recommendations or the best way to do this within Tapestry?

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


RE: Cache control results?

Posted by Patrick Casey <pa...@adelphia.net>.
	Couldn't you set up your own markup writer and have it write into a
stringwriter instead of the markup writer that comes in via the request?
That way you could still use the markupwriter helper functions.

		StringWriter sw = new StringWriter();
		PrintWriter w = new PrintWriter(sw);
		HTMLWriter elvis = new HTMLWriter(w);

	Then when you're done:

	String cachedOutput = sw.toString();

	Then push the cachedOuput through the request's own writer and
you're golden.

	--- Pat


-----Original Message-----
From: Michael Musson [mailto:musson.michael@gmail.com] 
Sent: Sunday, April 24, 2005 2:30 PM
To: Tapestry users
Subject: Re: Cache control results?

Yes, although the actual content of the control is quite lengthy and
generated recursively, and using the IMarkupWriter is a nice
convenience. If I go that route it would be nice to cache the writer
or at least its internal buffer.

But I wanted to make sure there is not a better way to do this since
it seems like a somewhat common performance optimization and Tapestry
contains direct support for other types of optimizations.

On 4/24/05, Patrick Casey <pa...@adelphia.net> wrote:
> 
>         Couldn't you just override the control's render method?

---------------------------------------------------------------------
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: Cache control results?

Posted by Michael Musson <mu...@gmail.com>.
Yes, although the actual content of the control is quite lengthy and
generated recursively, and using the IMarkupWriter is a nice
convenience. If I go that route it would be nice to cache the writer
or at least its internal buffer.

But I wanted to make sure there is not a better way to do this since
it seems like a somewhat common performance optimization and Tapestry
contains direct support for other types of optimizations.

On 4/24/05, Patrick Casey <pa...@adelphia.net> wrote:
> 
>         Couldn't you just override the control's render method?

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


RE: Cache control results?

Posted by Patrick Casey <pa...@adelphia.net>.
	Couldn't you just override the control's render method? Something
along the lines of:

Public class myCache() {
	Public static final String fData;

	Public static put(String data) {
		fData = data;
	}

	Public static get() {
		Return fData;
	}

	Public static flush() {
		fData = null;
	}
}

	Then in your render method:

protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
	
	String cached = myCache.get();
	If (cached != null) {
		Writer.print(cached);
	} else {
		// render component into a string buffer instead of the
stream
		myCache.put(buffer);
		writer.println(buffer.toString());
	}
	
}

-----Original Message-----
From: Michael Musson [mailto:musson.michael@gmail.com] 
Sent: Sunday, April 24, 2005 1:51 PM
To: tapestry-user@jakarta.apache.org
Subject: Cache control results?

I have a control that must do some intensive calls in order to render
itself. The actual content of the control will normally render
unchanged from call to call. There are only a few well defined spots
that could change the content of the control.

Ideally I would like to have the control save a copy of its output and
return this on renders until I call a method to clear the cache in
which case the control would redo the calls necessary to render
itself.

Is there a way to do caching like this directly in Tapestry or do you
have recommendations or the best way to do this within Tapestry?

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