From b8bb677cb57fb1e2f466b5075a05f5e6c1767f6a Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Mon, 2 Sep 2024 11:44:30 +1200 Subject: [PATCH] Plugin: Stop disabling the nginx cache The locale has been added to the proxy_cache_key used for the nginx cache, so we can now remove this workaround. See https://make.wordpress.org/systems/2021/03/26/vary-nginx-cache-by-wporg_locale-cookie-value/#comment-1942 --- wp-content/plugins/wporg-learn/inc/locale.php | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/wp-content/plugins/wporg-learn/inc/locale.php b/wp-content/plugins/wporg-learn/inc/locale.php index dded5644d..c231ff1e0 100644 --- a/wp-content/plugins/wporg-learn/inc/locale.php +++ b/wp-content/plugins/wporg-learn/inc/locale.php @@ -13,7 +13,6 @@ add_filter( 'wporg_learn_update_locale_data', __NAMESPACE__ . '\update_locale_data' ); add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\register_assets' ); add_filter( 'wporg_locale_switcher_options', __NAMESPACE__ . '\locale_switcher_options' ); -add_filter( 'wp_headers', __NAMESPACE__ . '\disable_caching' ); add_filter( 'posts_clauses', __NAMESPACE__ . '\wporg_archive_query_prioritize_locale', 10, 2 ); if ( ! wp_next_scheduled( 'wporg_learn_update_locale_data' ) ) { @@ -131,33 +130,6 @@ function( $locale ) { return $options; } -/** - * Disable nginx caching when locale switching is available. - * - * The nginx cache currently doesn't vary on the value of the cookie that gets set when a locale other than en_US is - * chosen. This causes problems when, e.g. a user visits the page with their browser language set to de_DE, which gets - * cached by nginx, and then another user visits with their browser set to en_US, and they are served the page in - * German regardless of they choose something else in the locale switcher. - * - * nginx does respect the Cache-Control header, though, so this offers a quick, hacky fix to the problem by turning - * off caching altogether. - * - * This should be removed if a way is found to vary the cache by the cookie value, e.g. to include the cookie value - * in the cache key as suggested in the discussion of this systems request: - * https://make.wordpress.org/systems/2021/03/26/vary-nginx-cache-by-wporg_locale-cookie-value/ - * - * @param array $headers - * - * @return array - */ -function disable_caching( $headers ) { - if ( class_exists( '\WordPressdotorg\LocaleDetection\Detector' ) ) { - $headers['Cache-Control'] = 'no-cache'; - } - - return $headers; -} - /** * Modify post type archive queries to prioritize content in the user's locale. *