Opened 10 years ago

Closed 5 years ago

#9334 closed New feature (wontfix)

The docs don't explain how django names cache keys

Reported by: simon@… Owned by:
Component: Documentation Version: 1.0
Severity: Normal Keywords: dceu2011
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no


For instance in a template fragment cache, how do i know the name of the cache key so i can delete it later?



Attachments (1)

ticket-9334.diff (2.2 KB) - added by Horst Gutmann <zerok@…> 7 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 10 years ago by simonredfern

After adding some print statements to the django cache files we found the answer to our question.

If you have a template with the following:

{% cache 3600 control_panel CACHE_KEY_PREFIX mem_id cache_modifier %}


{% endcache %}

Then the key that django generates will be like:

key = 'control_panel:%s:%s:%s' % (CACHE_KEY_PREFIX, mem_id, cache_modifier)





comment:2 Changed 9 years ago by Jacob

Triage Stage: UnreviewedAccepted

comment:3 Changed 7 years ago by Luke Plant

Severity: Normal
Type: New feature

comment:4 Changed 7 years ago by Horst Gutmann <zerok@…>

Easy pickings: unset
Owner: changed from nobody to Horst Gutmann <zerok@…>
UI/UX: unset

Changed 7 years ago by Horst Gutmann <zerok@…>

Attachment: ticket-9334.diff added

comment:5 Changed 7 years ago by Horst Gutmann <zerok@…>

Has patch: set

comment:6 Changed 7 years ago by Freark van der Bos

The part of the patch relating to the template cache key seems a-okay to me. However the middleware cache key portion sits uneasy with me since it mentions that it documents potentially unstable internals.

I wonder if this is in fact true. Parts of the key are generated with functions starting with an underscore, but from the outside it is generated with a single call to utils.cache.get_cache_key . I would assume that this functions output is stable. Considering that, I think the note about the key being potentially unstable could be remove.

Probably best that someone else also mentioned an opinion about that. :)

comment:7 Changed 7 years ago by Horst Gutmann <zerok@…>

Keywords: dceu2011 added

comment:8 Changed 7 years ago by Aymeric Augustin

Paraphrasing the cache key generation code in the docs, like this patch does, sounds inefficient to me. If a developer wants to determine a cache key, what is (s)he supposed to do: roll his own implementation, based on the docs? That doesn't make sense: the reference implementation is right there in Django!

In my opinion, the proper way to resolve this problem is to specify a public, stable API for computing cache keys, and document that.

This solution is:

  • user friendly: it involves less work for developers who need this feature,
  • developer friendly: we keep the freedom to change the underlying implementation if it contains design bugs, for instance if it's vulnerable to collisions under some circumstances (this example is gross, but you get the idea). For this reason, I'm afraid that the cure proposed by the current patch is worse than the disease :)

Does someone else have an opinion on this? (I won't touch the flags until I have more feedback.)

comment:9 Changed 7 years ago by Horst Gutmann <zerok@…>

Owner: Horst Gutmann <zerok@…> deleted
Patch needs improvement: set

@aaugustin: I totally agree with you. The patch I posted was originally a quick-shot and I intended to re-think it and talk with Russell or Jannis about this during the DjangoCon EU sprints about it, but sadly other things came in the way and I forgot about this issue. Sorry for that :-( I'm all for making the cache-key generation part of a public API. I've updated the flags and removed myself as owner since I probably won't have time to actually do the implementation.

comment:10 Changed 6 years ago by Tim Graham

It looks to me like #19320 is a suggestion (with a patch) for public cache API as discussed above. Perhaps we should close this ticket as a duplicate of that one?

comment:11 Changed 5 years ago by Tim Graham

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top