[Django] #29562: An idea for improving the template fragment cache

2 views
Skip to first unread message

Django

unread,
Jul 13, 2018, 1:32:46 AM7/13/18
to django-...@googlegroups.com
#29562: An idea for improving the template fragment cache
-----------------------------------------------+------------------------
Reporter: HongWeipeng | Owner: nobody
Type: New feature | Status: new
Component: Core (Cache system) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------------+------------------------
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]

--
Ticket URL: <https://code.djangoproject.com/ticket/29562>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 13, 2018, 1:55:52 AM7/13/18
to django-...@googlegroups.com
#29562: An idea for improving the template fragment cache
-------------------------------------+-------------------------------------

Reporter: HongWeipeng | Owner: nobody
Type: New feature | Status: new
Component: Core (Cache system) | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by HongWeipeng:

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>

Django

unread,
Jul 13, 2018, 9:38:54 AM7/13/18
to django-...@googlegroups.com
#29562: Allow the cache template tag to take a function that adds context data
---------------------------------+--------------------------------------
Reporter: HongWeipeng | Owner: nobody
Type: New feature | Status: closed
Component: Template system | Version: master
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Tim Graham):

* 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>

Reply all
Reply to author
Forward
0 new messages