←back to thread

149 points rbanffy | 1 comments | | HN request time: 2.515s | source
Show context
vldmrs ◴[] No.42151364[source]
At first I wanted to criticize the post, buuut after finishing reading it I actually liked it. Very concise and practical

ps - I didn’t know about template “cache” directive

replies(1): >>42154476 #
danpalmer ◴[] No.42154476[source]
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.

replies(2): >>42155864 #>>42156593 #
1. bdzr ◴[] No.42156593[source]
I haven't used it, but I think this is well targeted by https://github.com/dabapps/django-zen-queries.