Skip to content

Conversation

@solankisoftware89
Copy link

@solankisoftware89 solankisoftware89 commented Dec 6, 2025

Trac Ticket: https://core.trac.wordpress.org/ticket/64370

This PR enhances the WordPress Site Health page cache test by introducing
a robust cache header detection mechanism. The previous method could
produce false positives or negatives depending on the caching system used.

Changes include:

  • Added detect_cache_headers() method for strict, case-insensitive header matching
  • Improved support for common cache headers (x-cache, x-cache-status, cf-cache-status, x-litespeed-cache, x-varnish, etc.)
  • Updated get_test_page_cache() to use detect_cache_headers()
  • Prevents false positives when unrelated text contains words like "HIT" or "MISS"

Testing:

  1. Enable any caching layer (Varnish, NGINX fastcgi_cache, Cloudflare, LiteSpeed, host-level caching)
  2. Go to Tools → Site Health → Status
  3. Verify that page cache detection reflects the real server cache status

This PR is backward compatible and does not change existing Site Health UI behavior.

@github-actions
Copy link

github-actions bot commented Dec 6, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props solankisoftware.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Are you using AI to draft these changes?

Comment on lines -3415 to -3424

// Generic caching proxies (Nginx, Varnish, etc.)
'x-cache' => $cache_hit_callback,
'x-cache-status' => $cache_hit_callback,
'x-litespeed-cache' => $cache_hit_callback,
'x-proxy-cache' => $cache_hit_callback,
'via' => '',

// Cloudflare
'cf-cache-status' => $cache_hit_callback,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these removed from this list but the others are left intact?

* @param array $headers Response headers.
* @return bool Whether cache was detected.
*/
private function detect_cache_headers( $headers ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many PHPCS coding standards issues in this method.

'<p><a href="%1$s" target="_blank" rel="noreferrer">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
__( 'https://developer.wordpress.org/advanced-administration/performance/optimization/#caching' ),
__( 'Learn more about page cache' ),
/* translators: Hidden accessibility text. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this comment removed?

* @return array The test result.
*/
public function get_test_page_cache() {
$description = '<p>' . __( 'Page cache enhances the speed and performance of your site by saving and serving static pages instead of calling for a page every time a user visits.' ) . '</p>';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are all of these lines modified?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants