Code

Opened 2 years ago

Closed 17 months ago

#18191 closed New feature (fixed)

Don't consider Accept-Language when generating a cache key

Reported by: choongmin@… Owned by: ambv
Component: Core (Cache system) Version: master
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)

ignore_accept_language.diff (851 bytes) - added by choongmin@… 2 years ago.

Download all attachments as: .zip

Change History (6)

Changed 2 years ago by choongmin@…

comment:1 Changed 2 years ago by jezdez

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 2 years ago by jezdez

  • Needs documentation set
  • Needs tests set
  • Patch needs improvement set

comment:3 Changed 17 months ago by ambv

  • Owner changed from nobody to ambv
  • Status changed from new to assigned

comment:4 Changed 17 months ago by ambv

Pull request:

Remarks:

comment:5 Changed 17 months ago by Carl Meyer <carl@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 6a057e1595dfe45a0411c116f603801266c87395:

Fixed #18191 -- Don't consider Accept-Language redundantly in cache key.

Thanks to choongmin for the original patch.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.