List Info

Thread: Templates, filesystem, caching?




Templates, filesystem, caching?
user name
2007-12-17 14:49:42
Howdy,

A thought occurred to me today and I'm not 100% sure what
Django does
by default...

Similar to the idea that PHP parses scripts for each request
and
having an opcode cache can increase performance, I'm
wondering if
Django reads templates from the file system, parses them,
and then
does the context replacement on them for each and every
request.  And
if so, would there be some optimization to be gleaned by
caching the
parsed templates?  (Maybe optionally tied to DEBUG=False?)

Thanks,
Rob

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Templates, filesystem, caching?
user name
2007-12-17 15:37:19
htt
p://www.djangoproject.com/documentation/cache/

On 17 ÄÅË, 23:49, "Rob Hudson"
<treborhud...gmail.com> wrote:
> Howdy,
>
> A thought occurred to me today and I'm not 100% sure
what Django does
> by default...
>
> Similar to the idea that PHP parses scripts for each
request and
> having an opcode cache can increase performance, I'm
wondering if
> Django reads templates from the file system, parses
them, and then
> does the context replacement on them for each and every
request.  And
> if so, would there be some optimization to be gleaned
by caching the
> parsed templates?  (Maybe optionally tied to
DEBUG=False?)
>
> Thanks,
> Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Templates, filesystem, caching?
user name
2007-12-17 16:03:07
On 12/17/07, Alex Koshelev <daevaorngmail.com> wrote:
>
> htt
p://www.djangoproject.com/documentation/cache/

If I understand correctly, these cache the templates after
they have
been rendered.  What I'm curious about is if there is a way
to cache
templates before they are rendered so you can provide
different
contexts to them.  It seems like there would still be some
gains
involved -- a filesystem read, parsing the template into
nodes, etc.

Thanks,
Rob

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Templates, filesystem, caching?
user name
2007-12-17 16:32:50
Rob Hudson schrieb:
> If I understand correctly, these cache the templates
after they have 
> been rendered.  What I'm curious about is if there is a
way to cache 
> templates before they are rendered so you can provide
different 
> contexts to them.  It seems like there would still be
some gains 
> involved -- a filesystem read, parsing the template
into nodes, etc.

I've been wondernig the same thing. If I do {% include
"item.html" %} 
for 200 items, will item.html be re-read each time? Glancing
at the 
code, it appears so.

Michael

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Templates, filesystem, caching?
user name
2007-12-17 16:51:56
On Dec 17, 2007 4:03 PM, Rob Hudson <treborhudsongmail.com> wrote:
> If I understand correctly, these cache the templates
after they have
> been rendered.  What I'm curious about is if there is a
way to cache
> templates before they are rendered so you can provide
different
> contexts to them.  It seems like there would still be
some gains
> involved -- a filesystem read, parsing the template
into nodes, etc.

Manually call get_template() or select_template(), and stuff
the
resulting Template object into a module-global variable
somewhere.
Then just re-use it, calling render() with different
contexts, each
time you need it.


-- 
"Bureaucrat Conrad, you are technically correct -- the
best kind of correct."

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Templates, filesystem, caching?
user name
2007-12-18 00:20:09
Manually call get_template() or select_template(), and stuff
the
>resulting Template object into a module-global variable
somewhere.
>Then just re-use it, calling render() with different
contexts, each
>time you need it.

Along those lines, I recently noticed this bit of code that
swaps the
get_template fn out with one that does some caching:
http://ww
w.djangosnippets.org/snippets/507/



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Templates, filesystem, caching?
user name
2007-12-18 08:47:38
James Bennett schrieb:
> Manually call get_template() or select_template(), and
stuff the
> resulting Template object into a module-global variable
somewhere.
> Then just re-use it, calling render() with different
contexts, each
> time you need it.

Is there anything speaking against building that behaviour
directly into 
Django?

Michael

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Templates, filesystem, caching?
user name
2007-12-18 10:53:07
On 12/18/07, Michael Elsdörfer <michaelelsdoerfer.info> wrote:
> James Bennett schrieb:
> > Manually call get_template() or select_template(),
and stuff the
> > resulting Template object into a module-global
variable somewhere.
> > Then just re-use it, calling render() with
different contexts, each
> > time you need it.
>
> Is there anything speaking against building that
behaviour directly into
> Django?

I was curious of the same thing.  The only downside I see is
that
templates wouldn't "reload" automatically if you
changed them.  But
you could disable this when DEBUG=True.  And most people are
used to
the idea of reloading Apache if there is a change in a .py
file.

-Rob

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Templates, filesystem, caching?
user name
2007-12-21 15:50:23
After reading this thread the other day, I decided to write
up a patch
[1].

[1] http://code
.djangoproject.com/ticket/6262
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Templates, filesystem, caching?
user name
2007-12-21 16:22:52
Awesome!

What happens if you don't have caching enabled?

On 12/21/07, SmileyChris <smileychrisgmail.com> wrote:
>
> After reading this thread the other day, I decided to
write up a patch
> [1].
>
> [1] http://code
.djangoproject.com/ticket/6262

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-10] [11-19]

about | contact  Other archives ( Real Estate discussion Medical topics )