If the data acquisition process is time consuming (such as 3 seconds),
template caching has no helpful.
My idea is to allow provide a callback function to tell the cache how to
get the data. and only call the function when cache expires.
I have tried it many times and found out how to make the simplest changes
to complete this feature and ensure its compatibility.
Can you see this RP please? [https://github.com/django/django/pull/10176]
--
Ticket URL: <https://code.djangoproject.com/ticket/29562>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> There is a problem in using template fragment caching, that is, we need
> transfer `data` for template every time, even the data has been in cache.
>
> If the data acquisition process is time consuming (such as 3 seconds),
> template caching has no helpful.
>
> My idea is to allow provide a callback function to tell the cache how to
> get the data. and only call the function when cache expires.
>
> I have tried it many times and found out how to make the simplest changes
> to complete this feature and ensure its compatibility.
>
> Can you see this RP please? [https://github.com/django/django/pull/10176]
New description:
There is a problem in using template fragment caching, that is, we need
transfer `data` for template every time, even the data has been in cache.
If the data acquisition process is time consuming (such as 3 seconds),
template caching has no helpful.
My idea is to allow provide a callback function to tell the cache how to
get the data. and only call the function when cache expires.
Although custom tags can be used to get the data in the cache, custom tags
don't seem to handle html code very well.
I have tried it many times and found out how to make the simplest changes
to complete this feature and ensure its compatibility.
Can you see this RP please? [https://github.com/django/django/pull/10176]
--
--
Ticket URL: <https://code.djangoproject.com/ticket/29562#comment:1>
* status: new => closed
* component: Core (Cache system) => Template system
* resolution: => wontfix
Comment:
I think the proposed functionality is clever but it's too magical for my
liking. Allowing the template tag's "fragment name" to be a function whose
return value, if a dictionary, is added to the context looks like it
wouldn't help template readability.
Also, I don't think the enhancement is in line with the philosophy of the
Django template language, "the template system is meant to express
presentation, not program logic." What I would probably do is write a
custom get_data template tag and have that also take care of the caching.
Your template tag can call `template.render()`. See
TicketClosingReasons/UseSupportChannels for places to get help if needed.
If you disagree with my assessment, you can write to the
DevelopersMailingList to get other opinions.
--
Ticket URL: <https://code.djangoproject.com/ticket/29562#comment:2>