On this page
WP_Site_Health::get_page_cache_detail(): WP_Error|array
This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
Gets page cache details.
Return
WP_Error|array Page cache detail or else a WP_Error if unable to determine.
statusstringPage cache status. Good, Recommended or Critical.advanced_cache_presentboolWhether page cache plugin is available or not.headersstring[]Client caching response headers detected.response_timefloatResponse time of site.
Source
File: wp-admin/includes/class-wp-site-health.php. View all references
private function get_page_cache_detail() {
$page_cache_detail = $this->check_for_page_caching();
if ( is_wp_error( $page_cache_detail ) ) {
return $page_cache_detail;
}
// Use the median server response time.
$response_timings = $page_cache_detail['response_timing'];
rsort( $response_timings );
$page_speed = $response_timings[ floor( count( $response_timings ) / 2 ) ];
// Obtain unique set of all client caching response headers.
$headers = array();
foreach ( $page_cache_detail['page_caching_response_headers'] as $page_caching_response_headers ) {
$headers = array_merge( $headers, array_keys( $page_caching_response_headers ) );
}
$headers = array_unique( $headers );
// Page cache is detected if there are response headers or a page cache plugin is present.
$has_page_caching = ( count( $headers ) > 0 || $page_cache_detail['advanced_cache_present'] );
if ( $page_speed && $page_speed < $this->get_good_response_time_threshold() ) {
$result = $has_page_caching ? 'good' : 'recommended';
} else {
$result = 'critical';
}
return array(
'status' => $result,
'advanced_cache_present' => $page_cache_detail['advanced_cache_present'],
'headers' => $headers,
'response_time' => $page_speed,
);
}
Related
Uses
| Uses | Description |
|---|---|
| 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_good_response_time_threshold() wp-admin/includes/class-wp-site-health.php | Gets the threshold below which a response time is considered good. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
Used By
| Used By | Description |
|---|---|
| WP_Site_Health::get_test_page_cache() wp-admin/includes/class-wp-site-health.php | Tests if a full page cache is available. |
Changelog
| Version | Description |
|---|---|
| 6.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_site_health/get_page_cache_detail