Opened 17 years ago

Closed 15 years ago

Last modified 5 years ago

#5691 closed (fixed)

Add the active language to generate the cache key

Reported by: aaloy@… Owned by: aaloy
Component: Core (Cache system) Version: dev
Severity: Keywords: cache i18n jgd-blackboard
Cc: Ramiro Morales Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If you use a cache per parge approach and i18n, and you use a cookie to change your default language, if the page are cached previously you have some chances to get the wrong translation.

lang = translation.get_language()
cache_key = 'views.decorators.cache.cache_header.%s.%s_%s' % (key_prefix, iri_to_uri(request.path),lang)

Attachments (7)

django_utils_cache_patch.diff (2.4 KB ) - added by aaloy <aaloy@…> 17 years ago.
a patch with the proposed cache key
i18n_cache_keys_r7960_t5691.diff (2.7 KB ) - added by Andrew Badr 16 years ago.
cache.patch (2.5 KB ) - added by aaloy 16 years ago.
cache pacth to use lang in the cache key
patch_cache_i18n.patch (14.5 KB ) - added by aaloy 16 years ago.
patch and tests for cache i18n key generation
5691-use-lan-for-cache-key-r10338.diff (7.8 KB ) - added by Ramiro Morales 16 years ago.
Updated patch to port-r10335 and simplified tests
5691.patch (6.8 KB ) - added by yml 15 years ago.
update the patch against the latest trunk r12453
5691.2.patch (7.3 KB ) - added by aaloy 15 years ago.
Patch documentation

Download all attachments as: .zip

Change History (34)

by aaloy <aaloy@…>, 17 years ago

a patch with the proposed cache key

comment:1 by Jeremy Dunck, 17 years ago

aaloy: I don't think all keys should be affected by i18n. Perhaps there should be an alternate to the low-level cache that does add the active lang as a prefix?

comment:2 by Jacob, 17 years ago

Triage Stage: UnreviewedAccepted

This should probably only be done when USE_I18N == True, but otherwise this is a good idea.

comment:3 by Andrew Badr, 16 years ago

Owner: changed from nobody to Andrew Badr

comment:4 by Andrew Badr, 16 years ago

Needs documentation: set
Needs tests: set
Patch needs improvement: set

by Andrew Badr, 16 years ago

comment:5 by Andrew Badr, 16 years ago

Owner: changed from Andrew Badr to nobody

This patch works against trunk and checks the USE_I18N setting. However, this patch is current blocked by #730. Incoming requests need to use the Session middleware, then Locale, then Cache, so that the language is determined by the time we hit the cache middleware. However, outgoing responses need Session before Cache as well so that the cookie-based Vary headers can be set.

comment:8 by Andrew Badr, 16 years ago

Note that this is viable again after [8260]. Patch probably still works, but I didn't like the duplication of code, and it still needs tests and docs of course.

comment:9 by aaloy, 16 years ago

I'm working on a patch which could work as:

    cache_key = 'views.decorators.cache.cache_header.%s.%s' % (
                      key_prefix, iri_to_uri(request.path))
    if settings.USE_I18N:
       cache_key += ".%s" % translation.get_language()

I have tested using other ways of string concatenations and this one is the fast way (0.6 s for 106 interactions) for the kind of keys we're generating.

comment:10 by aaloy, 16 years ago

Owner: changed from nobody to aaloy
Status: newassigned

by aaloy, 16 years ago

Attachment: cache.patch added

cache pacth to use lang in the cache key

by aaloy, 16 years ago

Attachment: patch_cache_i18n.patch added

patch and tests for cache i18n key generation

comment:11 by aaloy, 16 years ago

Needs documentation: unset
Needs tests: unset

Added the patch an the tests to check that we generate the right keys and that middleware recovers different content depending on the language.

comment:12 by aaloy, 16 years ago

Patch needs improvement: unset

comment:13 by Ramiro Morales, 16 years ago

Cc: Ramiro Morales added

comment:14 by Jeremy Dunck, 16 years ago

Keywords: jgd-blackboard added

comment:15 by mrts, 16 years ago

/me wonders how the heck did my totally unrelated comments end up in this ticket!? My guess: nazi transgender aliens did it (it's still April 1 in my timezone, so don't you dare to disagree!).

by Ramiro Morales, 16 years ago

Updated patch to port-r10335 and simplified tests

comment:16 by Ramiro Morales, 16 years ago

I've updated Antoni Aloy's patch to apply cleanly after r10335 and simplified tests to only include what's needed to run them as part of the Django test suite, also fixed them so they don't break other tests leaving test environment umodified.

comment:17 by Flo Ledermann, 15 years ago

Any progress on checking this in? This is looking good, isn't it?

comment:18 by Jannis Leidel, 15 years ago

milestone: 1.2

by yml, 15 years ago

Attachment: 5691.patch added

update the patch against the latest trunk r12453

comment:19 by Jannis Leidel, 15 years ago

Needs documentation: set

I'm not sure if we break a promise changing the cache key in 1.2 or if it's ok since _generate_cache_header_key is undocumented API anyway.

Anyway, a change needs to be documented.

comment:20 by aaloy, 15 years ago

Resolution: fixed
Status: assignedclosed

jezdez in my oppinion this is not a new feature, is just a bug correction, as one may expect that on a multilingual content page the cache should depend also on the language. Anyway I would be glad to document it.

comment:21 by Jannis Leidel, 15 years ago

Resolution: fixed
Status: closedreopened

Please don't close the ticket if there wasn't an actual commit.

comment:22 by aaloy, 15 years ago

Opps. Sorry it was not my intention :(

by aaloy, 15 years ago

Attachment: 5691.2.patch added

Patch documentation

comment:23 by aaloy, 15 years ago

Needs documentation: unset

Added an updated patch with documentation warning about the new cache key generation. As is an internal feature I'm not really sure about if it has to be documented or not.

comment:24 by Jannis Leidel, 15 years ago

Resolution: fixed
Status: reopenedclosed

(In [12546]) Fixed #5691 - Adds the active language to the cache key. Thanks, Antoni Aloy, Ramiro Morales and Yann Malet.

comment:25 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

comment:11 by Aymeric Augustin, 13 years ago

In [17061]:

Made the cache locale-dependant when USE_L10N is True, even if USE_I18N is False. Refs #5691.

comment:12 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Easy pickings: unset
UI/UX: unset

In 258c88a:

Refs #5691 -- Made cache keys independent of USE_L10N.

This mostly reverts af1893c4ff8fdbf227a43a559d90bb1c1238b01a.

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