Opened 16 years ago
Closed 11 years ago
#9334 closed New feature (wontfix)
The docs don't explain how django names cache keys
Reported by: | 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 |
Description
For instance in a template fragment cache, how do i know the name of the cache key so i can delete it later?
cheers,
Simon.
Attachments (1)
Change History (12)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:4 by , 13 years ago
Easy pickings: | unset |
---|---|
Owner: | changed from | to
UI/UX: | unset |
by , 13 years ago
Attachment: | ticket-9334.diff added |
---|
comment:5 by , 13 years ago
Has patch: | set |
---|
comment:6 by , 13 years ago
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 by , 13 years ago
Keywords: | dceu2011 added |
---|
comment:8 by , 13 years ago
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 by , 13 years ago
Owner: | removed |
---|---|
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 by , 12 years ago
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 by , 11 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
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)
e.g.
control_panel:sitename-LIVE:1:x
cheers,
Simon.