Title: WP_Site_Health::get_page_cache_headers
Published: November 2, 2022
Last modified: May 20, 2026

---

# WP_Site_Health::get_page_cache_headers(): array<string,

## In this article

 * [Return](https://developer.wordpress.org/reference/classes/wp_site_health/get_page_cache_headers/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_site_health/get_page_cache_headers/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/classes/wp_site_health/get_page_cache_headers/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/classes/wp_site_health/get_page_cache_headers/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_site_health/get_page_cache_headers/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_site_health/get_page_cache_headers/?output_format=md#wp--skip-link--target)

Returns a mapping from response headers to an optional callback to verify if page
cache is enabled or not.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_site_health/get_page_cache_headers/?output_format=md#return)󠁿

 array<string, ?callable> Mapping of page caching headers and their (optional) verification
callbacks.
 A null value means a simple existence check is used for the header.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_site_health/get_page_cache_headers/?output_format=md#source)󠁿

    ```php
    public function get_page_cache_headers(): array {

    	$cache_hit_callback = static function ( $header_value ) {
    		return 1 === preg_match( '/(^| |,)HIT(,| |$)/i', $header_value );
    	};

    	$cache_headers = array(
    		// Standard HTTP caching headers.
    		'cache-control'          => static function ( $header_value ) {
    			return (bool) preg_match( '/max-age=[1-9]/', $header_value );
    		},
    		'expires'                => static function ( $header_value ) {
    			return strtotime( $header_value ) > time();
    		},
    		'age'                    => static function ( $header_value ) {
    			return is_numeric( $header_value ) && $header_value > 0;
    		},
    		'last-modified'          => null,
    		'etag'                   => null,
    		'via'                    => null,

    		/**
    		 * Custom caching headers.
    		 *
    		 * These do not seem to be actually used by any caching layers. There were first introduced in a Site Health
    		 * test in the AMP plugin. They were copied into the Performance Lab plugin's Site Health test before they
    		 * were merged into core.
    		 *
    		 * @link https://github.com/ampproject/amp-wp/pull/6849
    		 * @link https://github.com/WordPress/performance/pull/263
    		 * @link https://core.trac.wordpress.org/changeset/54043
    		 */
    		'x-cache-enabled'        => static function ( $header_value ) {
    			return ( 'true' === strtolower( $header_value ) );
    		},
    		'x-cache-disabled'       => static function ( $header_value ) {
    			return ( 'on' !== strtolower( $header_value ) );
    		},

    		/**
    		 * CloudFlare.
    		 *
    		 * @link https://developers.cloudflare.com/cache/concepts/cache-responses/
    		 */
    		'cf-cache-status'        => $cache_hit_callback,

    		/**
    		 * Fastly.
    		 *
    		 * @link https://www.fastly.com/documentation/reference/http/http-headers/X-Cache/
    		 */
    		'x-cache'                => $cache_hit_callback,

    		/**
    		 * LightSpeed.
    		 *
    		 * @link https://docs.litespeedtech.com/lscache/devguide/controls/#x-litespeed-cache
    		 */
    		'x-litespeed-cache'      => $cache_hit_callback,

    		/**
    		 * OpenResty srcache-nginx-module.
    		 *
    		 * The `x-srcache-store-status` header indicates if the response was stored in the cache.
    		 * Valid values include `STORE` and `BYPASS`.
    		 *
    		 * The `x-srcache-fetch-status` header indicates if the response was fetched from the cache.
    		 * Valid values include `HIT`, `MISS`, and `BYPASS`.
    		 *
    		 * @link https://github.com/openresty/srcache-nginx-module
    		 */
    		'x-srcache-store-status' => static function ( $header_value ) {
    			return 'store' === strtolower( $header_value );
    		},
    		'x-srcache-fetch-status' => $cache_hit_callback,

    		/**
    		 * Nginx.
    		 *
    		 * @link https://blog.nginx.org/blog/nginx-caching-guide
    		 * @link https://www.inmotionhosting.com/support/website/nginx-cache-management/
    		 */
    		'x-cache-status'         => $cache_hit_callback,
    		'x-proxy-cache'          => $cache_hit_callback,

    		/**
    		 * Varnish Cache.
    		 *
    		 * A header with a single number indicates it was not cached. If there are two numbers (or more), then this
    		 * indicates the response was cached.
    		 *
    		 * @link https://vinyl-cache.org/docs/2.1/faq/http.html
    		 * @link https://www.fastly.com/documentation/reference/http/http-headers/X-Varnish/
    		 * @link https://www.linuxjournal.com/content/speed-your-web-site-varnish
    		 */
    		'x-varnish'              => static function ( $header_value ) {
    			return 1 === preg_match( '/^\d+ \d+/', $header_value );
    		},
    	);

    	/**
    	 * Filters the list of cache headers supported by core.
    	 *
    	 * This list indicates how each of the specified headers will be checked to indicate if a page cache is enabled
    	 * or not. WordPress checks for each of the headers in the returned array. If the callback is provided, it will
    	 * be passed the value for the corresponding header and return a boolean value indicating if the header suggests
    	 * that a cache is active. If the value is `null` for the header, then WordPress will assume that a cache is
    	 * active if the header is present, regardless of its value.
    	 *
    	 * @since 6.1.0
    	 *
    	 * @param array<string, ?callable> $cache_headers Mapping from cache-related HTTP headers to whether they
    	 *                                                indicate if a page cache is enabled for the site. `null`
    	 *                                                indicates caching in the presence of the header; a callback is
    	 *                                                provided the header’s value and should return `true` if it
    	 *                                                implies that a cache is active.
    	 */
    	return (array) apply_filters( 'site_status_page_cache_supported_cache_headers', $cache_headers );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-site-health.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-admin/includes/class-wp-site-health.php#L3478)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-admin/includes/class-wp-site-health.php#L3478-L3596)

## 󠀁[Hooks](https://developer.wordpress.org/reference/classes/wp_site_health/get_page_cache_headers/?output_format=md#hooks)󠁿

 [apply_filters( ‘site_status_page_cache_supported_cache_headers’, array<string,  )](https://developer.wordpress.org/reference/hooks/site_status_page_cache_supported_cache_headers/)

Filters the list of cache headers supported by core.

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_site_health/get_page_cache_headers/?output_format=md#related)󠁿

| Uses | Description | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

| Used by | Description | 
| [WP_Site_Health::check_for_page_caching()](https://developer.wordpress.org/reference/classes/wp_site_health/check_for_page_caching/)`wp-admin/includes/class-wp-site-health.php` |

Checks if site has page cache enabled or not.

  | 
| [WP_Site_Health::get_test_page_cache()](https://developer.wordpress.org/reference/classes/wp_site_health/get_test_page_cache/)`wp-admin/includes/class-wp-site-health.php` |

Tests if a full page cache is available.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_site_health/get_page_cache_headers/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_site_health%2Fget_page_cache_headers%2F)
before being able to contribute a note or feedback.