News for hackers. Stuff that matters.
Re:The Practical Guide to Scaling Django by danpalmer on Saturday November 16, 2024 @12:12AM (#42154476)
FWIW, I'd advise against template caching. It's awkward to cache bust, and a network round trip to your cache will almost certainly be more expensive than the Python operations to render the template, even with stock Django templating which is slow.

The only place it's possible worth it is if you do a lot of database queries from your template rendering, and you're therefore caching database results (as rendered text). In that case, it's an easy patch. However a much better solution is to fetch all database results up front.

In my previous company we had a very significant Django codebase with plenty of templating, and found that using the templating system for (lazy loaded) database queries or caching was more hassle than it was worth and avoided it as much as possible. Treating template rendering as a pure CPU bound function was always better.

Re:The Practical Guide to Scaling Django by nprateem on Saturday November 16, 2024 @06:25AM (#42155864)
It'd be faster to retrieve from a cache than to make a round-trip to a DB to get the data needed for templating.
Re:The Practical Guide to Scaling Django by telgareith on Saturday November 16, 2024 @08:44AM (#42156365)
[assumption]
Re:The Practical Guide to Scaling Django by danpalmer on Saturday November 16, 2024 @07:55PM (#42161011)
My point was that you shouldn't be doing DB queries in the template. If you're doing the DB queries before templating then you should also be doing the cache queries before templating too.
Re:The Practical Guide to Scaling Django by bdzr on Saturday November 16, 2024 @09:25AM (#42156593)
I haven't used it, but I think this is well targeted by https://github.com/dabapps/django-zen-queries.