Make WordPress Core

Opened 7 weeks ago

Last modified 6 weeks ago

#64370 new enhancement

Response header detection in page cache test for Site Health should be more robust

Reported by: westonruter's profile westonruter Owned by:
Milestone: 7.0 Priority: normal
Severity: normal Version: 6.1
Component: Site Health Keywords: has-patch
Focuses: performance Cc:

Description (last modified by westonruter)

This is a follow-up to #63748. See PR comment from @dmsnell:

I wish that the $cache_hit_callback were more robust than it is, since it also matches on values like “this cache is *hit, don’t use it” and “not a hit” but that’s not part of this ticket or work.

would be awesome to have some example strings from each of these new headers as a comment to the right of them.

for example, the varnish docs suggest that the _full_ match is hit, meaning we could add => static function ( $v ) { return 'hit' === $v; } /** @see https://www.varnish-software.com/developers/tutorials/logging-cache-hits-misses-varnish/ */

the extra examples are icing on the cake and not necessary here.

according to this random survey x-cache-status is expected to only contain hit, though for x-cache there is an insignificant but measureable count of requests containing HIT, MISS

Also, in Slack:

the only thing that really caught my eye is that we’re needly allocating to do case-insensitive compare instead of calling stripos()

Attachments (1)

64370.patch (262.8 KB) - added by solankisoftware 7 weeks ago.
FIX :: Response header detection in page cache test for Site Health should be more robust

Download all attachments as: .zip

Change History (6)

#1 @westonruter
7 weeks ago

  • Description modified (diff)

This ticket was mentioned in Slack in #core-performance by westonruter. View the logs.


7 weeks ago

@solankisoftware
7 weeks ago

FIX :: Response header detection in page cache test for Site Health should be more robust

#3 @solankisoftware
7 weeks ago

  • Keywords has-patch added; needs-patch removed

Replaces the old string-based cache header detection in Site Health with a more robust method.
Adds case-insensitive matching, supports additional cache headers, and prevents false positives.
Improves accuracy across Varnish, NGINX, Cloudflare, LiteSpeed, and host-level caching systems.

#4 @westonruter
6 weeks ago

  • Keywords needs-patch added; has-patch removed

@solankisoftware Your patch seems malformed. It is introducing an entire new file. Please consider opening a pull request instead to facilitate review and testing.

This ticket was mentioned in PR #10606 on WordPress/wordpress-develop by @solankisoftware.


6 weeks ago
#5

  • Keywords has-patch added; needs-patch removed

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.

Note: See TracTickets for help on using tickets.