|
Hello
One technique I have very successfully implemented in Django and Rails and used in production was rendering certain pages to an ordinary string which is put into a (distributed) cache (like memcached) and retrieved on subsequent requests - bypassing the entire rendering pipeline and reducing the work on the application server to socket read/write cycle (simplified). The technique is described in detail in this article: http://www.igvita.com/2008/02/11/nginx-and-memcached-a-400-boost/ Unfortunately I cannot find a way to implement the same pattern in Grails - at least not for complete pages including the applied template. According to Graeme g.render is and never was supposed to support this. So what's left?I admit I am no servlet expert but willing to lern :) Any hints would be appreciated. - Oliver |
|
You could probably implement this pretty easily by
hooking into "afterFilters" Specifically you would want the before and afterView actions. http://www.grails.org/Filters Then I would take the output and then create a hash as a key and then store it in memcached or ehCache. Then the only part I would need to tinker with to figure out is how to stop request processing in the beforeFilter and serve the cached content. You could probably figure out some clever scheme with a redirect to a special controller action for this that would work. Implementing this as a plugin would probably be the way to go. There was an older cache plugin that attempted to cache page fragments, but not sure it has seen much activity in quite a while. On Wed, Jan 20, 2010 at 1:33 PM, oliverw <[hidden email]> wrote:
|
|
One option that you might want to look at is ehcache-web which can cache the whole response or just page fragments. I've been looking at it lately and am looking at creating a plugin but just haven't had the time lately. You can easily distribute ehcache so all the web nodes can have access to the cached response. You do need to override the creating of the keys method in the current filter but this is super easy. Most of the information is already on the ehcache-web website so have a look. If you need more information just let me know.
Glenn On Wed, Jan 20, 2010 at 7:20 PM, Daniel Honig <[hidden email]> wrote: You could probably implement this pretty easily by |
|
Ok, that's the plugin which has just been released on grails.org ?
Thank you !! On Wed, Jan 20, 2010 at 9:27 PM, Glenn Saqui <[hidden email]> wrote: One option that you might want to look at is ehcache-web which can cache the whole response or just page fragments. I've been looking at it lately and am looking at creating a plugin but just haven't had the time lately. You can easily distribute ehcache so all the web nodes can have access to the cached response. You do need to override the creating of the keys method in the current filter but this is super easy. Most of the information is already on the ehcache-web website so have a look. If you need more information just let me know. -- Vincent Wiencek [hidden email] |
|
In reply to this post by oliverw
On 20.01.2010 20:33, oliverw wrote:
> Hello > > One technique I have very successfully implemented in Django and Rails and > used in production was rendering certain pages to an ordinary string which > is put into a (distributed) cache (like memcached) and retrieved on > subsequent requests - bypassing the entire rendering pipeline and reducing > the work on the application server to socket read/write cycle (simplified). > The technique is described in detail in this article: > http://www.igvita.com/2008/02/11/nginx-and-memcached-a-400-boost/ > > Unfortunately I cannot find a way to implement the same pattern in Grails - > at least not for complete pages including the applied template. According to > Graeme g.render is and never was supposed to support this. So what's left?I > admit I am no servlet expert but willing to lern :) Any hints would be > appreciated. > > - Oliver > I've used Apache httpd as a caching reverse proxy. Here's some instructions about how to set it up in Ubuntu: http://quest4grail.blogspot.com/2009/08/apache-config-for-aggressive-reverse.html It would be cool to have a mature ESI (http://en.wikipedia.org/wiki/Edge_Side_Includes) processor available in open source space. It would solve the personalization issue (you could show the logged in user's name on each page and still cache most pages). Varnish has basic ESI support: http://varnish.projects.linpro.no/wiki/ESIfeatures . Too bad Apache httpd doesn't support ESI . The caching reverse proxy pattern is one of the most inexpensive ways to scale a Grails based site (or a site built with any technology). It's very easy to set-up for public sites that are stateless (don't use session state , user login etc.). Regards, Lari --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
This post has NOT been accepted by the mailing list yet.
In reply to this post by Daniel Honig
Sorry for replying so late Daniel. Thanks for your input. After inspecting the response object in the afterView closure I found a way to get hold of the rendered view with fully applied layout. But I'm not sure if I should go that route because it involves accessing a private property - which is of course no problem in groovy. Opinions or suggestion? Graeme?
class CacheFilter { def filters = { cacheFilter(controller: '*', action: '*') { afterView = { // at this point the 'response' variable will of type GrailsContentBufferingResponse // this class has a private property 'pageResponseWrapper' of type GrailsPageResponseWrapper // which provides us access to the rendered view println response.pageResponseWrapper.contents } } } } |
|
This post has NOT been accepted by the mailing list yet.
update: response.content.page works just as well and involves no private properties.
|
|
This post has NOT been accepted by the mailing list yet.
Another update: I was blind. The content returned does not have the layout applied which makes it worthless for this purpose. Is there no way in Grails to something as simple as the final rendered page output?
|
|
The layout is applied in a separate ServletFilter (GrailsPageFilter). If you want to capture the full response, you will have to use a ServletFilter. I think that the grails plugin cachefilter already does this: http://www.grails.org/plugin/cachefilter .
Regards, Lari |
|
This post has NOT been accepted by the mailing list yet.
Thank Lari. At least I know where to look further.
On Mon, Feb 1, 2010 at 6:20 AM, Lari Hotari [via Grails] <[hidden email]> wrote: The layout is applied in a separate ServletFilter (GrailsPageFilter). If you want to capture the full response, you will have to use a ServletFilter. I think that the grails plugin cachefilter already does this: http://www.grails.org/plugin/cachefilter . -- Oliver Weichhold Senior Consultant & Developer |
| Powered by Nabble | Edit this page |
