Code

#19253 closed Cleanup/optimization (fixed)

Refactor keyfunc from template cache tag

Reported by: nosa_manuel Owned by: oinopion
Component: Template system Version: master
Severity: Normal Keywords: sprint2013
Cc: tomek@…, chrismedrela Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The code to generate keys is stuck in the middle of the render method of the cache tag node, and should be extracted so that it can be used to invalidate template cache fragments.

Patch available in a pull request here: https://github.com/django/django/pull/482

Attachments (0)

Change History (5)

comment:1 Changed 18 months ago by ptone

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

The only reason to refactor this is to expose it as public API - and so would need a slightly different approach.

The func should be exposed somewhere else - not in the template tag, perhaps in new django.core.cache.utils module

To avoid confusion with the make_key function on cache backends - it should be more explicitly named as make_templatefragment_key

And it should be documented at the end of https://docs.djangoproject.com/en/dev/topics/cache/#template-fragment-caching - presumably explaining the use case for, presumably, cache invalidation based on the change of something else in the project.

Could you explain why you can't achieve what you are after with using template variables for the vary-on args that are set by the view, which would cache a new fragment as needed?

comment:2 Changed 14 months ago by oinopion

  • Cc tomek@… added
  • Keywords sprint2013 added
  • Owner changed from nobody to oinopion
  • Status changed from new to assigned

comment:3 Changed 14 months ago by oinopion

comment:4 Changed 14 months ago by chrismedrela

  • Cc chrismedrela added
  • Triage Stage changed from Accepted to Ready for checkin

comment:5 Changed 14 months ago by Honza Kral <honza.kral@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 99edbe0e279166db82caaf545ef92d5446a6a07e:

Fixed #19253 -- Extracted template cache key building logic

Introduced a public function
django.core.cache.utils.make_template_fragment_key
Thanks @chrismedrela for fruitful cooperation.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.