On Fri, May 13, 2011 at 3:01 PM, Nan <ringe...@gmail.com> wrote:
> I'm working on a site where about 95% of the pages are "static" and
> change no more than once a week, and should therefore be cached;
> however, there are a couple blocks in the base template (login forms,
> blocks that load randomized content, etc) that shouldn't be cached.
> Is there any way to enable cache on everything else but disable it on
> those blocks?  I feel like it's extremely inefficient to have to hit
> the database for page data on every view of a static page because of
> that.
>
> I suppose that the static page query results could be cached, but a)
> they'd still have to be re-rendered, and b) that would mean updating
> every one of about 30 views, and any views built in the future, which
> doesn't feel very DRY or maintainable.  Am I missing something, or
> misunderstanding something fundamental about how Django's cache
> framework works?

The term you're looking for is "two-phase rendering": you basically
want to render the template once, cache that, and then later render
just a bit of it again.

Adrian wrote about the technique some time ago; see
http://www.holovaty.com/writing/django-two-phased-rendering/. There
are some tips there for building something by hand, or you could
django-phased, which seems to work out-of-the-box:
https://github.com/codysoyland/django-phased.

The technique I usually use is to use Varnish's ESI features
(http://varnish.projects.linpro.no/wiki/ESIfeatures) and push the
caching out to the edge. There's a writeup of a technique similar to
mine at http://yml-blog.blogspot.com/2010/01/esi-using-varnish-and-django.html,
and again there's an app that appears to provide the Django-y bits:
https://bitbucket.org/mlhamel/django-esi/src.

Good luck!

Jacob

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

Reply via email to