Opened 13 years ago
Closed 12 years ago
#18191 closed New feature (fixed)
Don't consider Accept-Language when generating a cache key
Reported by: | Owned by: | Łukasz Langa | |
---|---|---|---|
Component: | Core (Cache system) | Version: | dev |
Severity: | Normal | Keywords: | cache vary i18n |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | yes | Patch needs improvement: | yes |
Easy pickings: | yes | UI/UX: | no |
Description
Currently, Django makes different cache keys for different Accept-Language headers. But different Accept-Language headers may be resolved into the same language. For example, see the following Accept-Language headers collected in my site for last 30 minutes:
- en-us
- en-US
- en-US,en;q=0.8
- en-US,en;q=0.8,ko;q=0.6
- fr-fr
- ja-JP
- ko
- ko, en
- ko-kr
- ko-KR
- ko-KR, en-US
- ko-kr,ko;q=0.8,en-us;q=0.5,en;q=0.3
- ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4
- ko;q=1.0,en;q=0.5
It makes the cache system inefficient for multilingual sites. Since there is utils.cache._i18n_cache_key_suffix, it is unnecessary and redundant to include Accept-Language headers in a cache key. We should ignore them in utils.cache.learn_cache_key.
Note that not adding "Vary: Accept-Language" from the first place in middleware.locale.process_response is not a good solution because of proxy servers.
The attached patch removes Accept-Language from headerlist before generating a cache key.
If the patch is rejected, users like me should at least be able to ignore them.
Attachments (1)
Change History (6)
by , 13 years ago
Attachment: | ignore_accept_language.diff added |
---|
comment:1 by , 13 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 13 years ago
Needs documentation: | set |
---|---|
Needs tests: | set |
Patch needs improvement: | set |
comment:3 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 12 years ago
comment:5 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Pull request:
Remarks:
Vary
so I sorted those headers while creating the cache key to make sure the number of combinations is the smallest possible