Opened 7 years ago

Closed 7 years ago

Last modified 5 years ago

#13014 closed (fixed)

Document using LANGUAGE_CODE with the cache template tag

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

Description

Issue:
The cache templatetag does not take into account the Language (i18n).

Solution:
The cache templatetag[1] should be updated to use the new _i18n_cache_key_suffix[2]. Given context in which this code is evaluated the request is not required :
cache_key = _i18n_cache_key_suffix(request=None, cache_key):

This is in fact a follow up this ticket : #5691 which reported a similar issue with the cache middleware. the infrastructure for this change has been added in r12624 and r12546

[1]http://code.djangoproject.com/browser/django/trunk/django/templatetags/cache.py#L28
[2] http://code.djangoproject.com/browser/django/trunk/django/utils/cache.py#L137

Attachments (2)

13014.diff (5.8 KB) - added by Chris Beaven 7 years ago.
13014_doc.diff (1.4 KB) - added by anonymous 7 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 7 years ago by Chris Beaven

milestone: 1.2
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

I think that it makes sense to achieve parity between decorator and template tag caching before 1.2

Changed 7 years ago by Chris Beaven

Attachment: 13014.diff added

comment:2 Changed 7 years ago by Chris Beaven

Component: UncategorizedTemplate system
Has patch: set
Owner: changed from nobody to Chris Beaven
Status: newassigned
Summary: Cache templatetag and i18nCache templatetag is not locale aware
Version: 1.1SVN

comment:3 Changed 7 years ago by Chris Beaven

Needs documentation: set
Triage Stage: AcceptedDesign decision needed

Yann brought up the point that maybe a user should be told to just do this manually by passing the locale as a cache argument.

Some short docs should be added to explain either the difference in behaviour or the parity.

comment:4 Changed 7 years ago by Jannis Leidel

IMO, we should simply mention in the docs that this works well:

{% cache 60 welcome request.LANGUAGE_CODE %}
    {% trans "Welcome to zombo.com" %}
{% endcache %}

It's not exactly the same as the cache/middleware approach, but that's true for fragment caching anyway -- it's built to be flexible in contrast to out of the box caching of the middleware/decorator mechanism.

comment:5 Changed 7 years ago by Chris Beaven

You'd also want to mention that they'd have to pass request in the context, or use the request context processor & a requestcontext.

But sure, if that's enough then someone can just write some nice docs :)

comment:6 Changed 7 years ago by Jacob

Doesn't the i18n context processor put LANGUAGE_CODEin the context? Seems to me that's the right approach -- "explicit is better than implicit". Any reason we should do anything more than a doc addition?

comment:7 Changed 7 years ago by Chris Beaven

Component: Template systemDocumentation
Has patch: unset
Needs documentation: unset
Owner: Chris Beaven deleted
Status: assignednew
Summary: Cache templatetag is not locale awareDocument using LANGUAGE_CODE with the cache template tag
Triage Stage: Design decision neededAccepted

Good point, Jacob. Definitely just a documentation job.

comment:8 Changed 7 years ago by anonymous

Has patch: set

comment:9 Changed 7 years ago by Chris Beaven

Has patch: unset

The patch doesn't address the decision made to just document this behavior, Mr Anonymous.

Changed 7 years ago by anonymous

Attachment: 13014_doc.diff added

comment:10 Changed 7 years ago by fgutierrez@…

Cc: fgutierrez@… added
Has patch: set

Just added a doc patch. Hope it is correct.

comment:11 Changed 7 years ago by Jannis Leidel

Resolution: fixed
Status: newclosed

(In [12787]) Fixed #13014 - Added section about how to use the language code with fragement caching. Thanks for the initial patch, fgutierrez.

comment:12 Changed 5 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top