Looking at the code Carlton provided sounds like it meets what was being requested, but it fails "There should be one-- and preferably only one --obvious way to do it." in that it wasn't immediately obvious, but adding the cacheif tag would lead to more than one way. Therefore I'm suggesting that either the new template tag gets added or this gets documented in https://docs.djangoproject.com/en/4.1/topics/cache/#template-fragment-caching
. I think the suggestion from Carlton is readable enough that it just should be documented as an example, so it becomes more obvious how to put it together when glancing at this section.
This section also mentions that "The fragment is cached forever if timeout is
None." But it's missing the "A
0 won’t cache the value." Note that appears in other references for the timeout value.
PS: If I remember, I'll make a PR for those when I get home from work, but I'm more than happy for someone to beat me to it.