On Feb 2, 3:07 pm, "Andy (Zenom)" <[email protected]> wrote:
> Someone in IRC said write a wrapper, but having a hard time wrapping
> my head around this, since the data I need to cache is all in the
> controller and there could be multiple queries etc. If I wrap the
> render method somehow, then the queries are still going to run before
> the cache render function would run.

I do almost the same thing in a few places on ArtWeLove.com

The two techniques I use:

- In most instances, Pylons writes a .php file.  Yeah, I hate that
damn language too -- but running php through nginx+fcgi with a couple
of optimizations makes it considerably faster than Pylons.  Nginx just
knows which directories to serve as php, and which to not.  If there
are a handful of variables , i'll often have pylons write out a php
file that is just a dict/array of the variables in php.

- In some instances, I just use beaker caching. this is confusing to
explain, so i'll try to illustrate with code that handles 1 'heavy db
call' fragment.  In practice, our splash page has 3 zones that we do
this to.

index-fragment-a.mako
    % for item in dbcall: do stuff

index.mako
    <%inherit file="/@site-template.mako"/>
    ${h.literal(c.rendered_fragment__a)}

splash.py
    def splash(self):
        page_cache= cache.get_cache('awl.page',cache_type='memory')
        c.rendered_fragment__a = page_cache.get_value( 'splash:a',
createfunc= self._splash_generate_fragment_a ,
expiretime=g.awl_cache_expiry_page )
        c.code= CODE
        return render ('/index.mako')

    def _splash_generate_fragment_a(self):
        self._dbSessionSetup('read')
        lots of db calls
        return render ('/index-fragment-a.mako')

does that make sense?

There's a third technique you could do as well -- you could just
render the page and store in beaker , and either have that template
generate a mako template ( by escaping certain interpolation stuff )
or just some raw html with a string like ####CODE##### then do

    def splash(self):
        page_cache= cache.get_cache()
        template= page_cache.get_value( 'splash:a', createfunc=
self._generate )
        template= template.replace( '####CODE####', code )
        return template

i think there's a way to render() on a string too (instead of a file )
so it could be...

        c.code= CODE
        return render( string_template= template )

i have no idea what the params would be -- i made up
"string_template"...  but i'm pretty sure i've seen that in the
templating source code.

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to