On Feb 16, 2013, at 9:16 AM, Christophe Pettus wrote:

> 
> On Feb 16, 2013, at 8:50 AM, ozgur yilmaz wrote:
> 
>> I'm using template fragment caching in my project. I'm wondering what
>> the view function do when template fragment caching is active? Are
>> queries in the view function be executed? Or bypass the queries and
>> read the cached fragment?
> 
> The view function is not bypassed when template fragment caching is active.  
> Thus, if you do a bunch of expense queries to populate the context, those 
> queries will still happen; the only step that is skipped is the actual 
> rendering of the template.  It's often a good idea to have those expense 
> queries be done on-demand in a callable that is invoked by the template, so 
> they are only called when the template is actually rendered.

Of course, QuerySets are (usually) lazy, so if you pass them in to the template 
via the context unevaluated, and that fragment of the template is cached, the 
query won't be executed.

--
-- Christophe Pettus
   x...@thebuild.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to