作為 WordPress 6.1 版本的一部分,性能團(tuán)隊(duì)添加了兩項(xiàng)站點(diǎn)健康檢查(持久對(duì)象緩存和頁(yè)面緩存)。這些檢查之前在Performance Lab 插件中進(jìn)行了測(cè)試。您可以在原始提案中閱讀更多關(guān)于它們的信息。
這兩項(xiàng)檢查都將僅在生產(chǎn)環(huán)境中運(yùn)行。

持久對(duì)象緩存
這項(xiàng)新檢查確定站點(diǎn)是否使用持久對(duì)象緩存,并在對(duì)站點(diǎn)有意義時(shí)推薦它。它還鏈接到為檢查創(chuàng)建的支持資源。
已包含一些過濾器,旨在讓托管服務(wù)提供商提供有關(guān)其環(huán)境的更具體的步驟。
管理員可以使用site_status_persistent_object_cache_url?過濾器將原始 WordPress 指南替換為他們自己的指南。
/**
* Filter the Persistent object cache URL.
*/
add_filter( 'site_status_persistent_object_cache_url', function() {
return 'https://awesomewphosting.com/optimization/persistent-object-cache';
} );
還可以使用site_status_persistent_object_cache_notes過濾器自定義注釋以推薦他們首選的對(duì)象緩存解決方案。
/**
* Update the persistent object cache notes.
*/
add_filter( 'site_status_persistent_object_cache_notes', function( $notes ) {
$notes = __( 'The updated notes can go here as text.', 'text-domain' );
return $notes;
} );
新增的 site_status_persistent_object_cache_thresholds過濾器允許修改 WordPress 認(rèn)為使用持久對(duì)象緩存有益的閾值。
/**
* Override the whole $thresholds array, or any specific indexes as required.
*/
add_filter( 'site_status_persistent_object_cache_thresholds', function( $thresholds ) {
$thresholds = array(
'alloptions_count' => 600,
'alloptions_bytes' => 200000,
'comments_count' => 2000,
'options_count' => 2000,
'posts_count' => 2000,
'terms_count' => 2000,
'users_count' => 2000,
);
return $thresholds;
} );
或者,site_status_should_suggest_persistent_object_cache是一個(gè)短路(short-circuit)過濾器,它允許使用完全自定義的邏輯來(lái)確定持久對(duì)象緩存是否對(duì)站點(diǎn)有意義。
/**
* Opt in for suggesting the persistent object cache
*/
add_filter( 'site_status_should_suggest_persistent_object_cache', '__return_true' );
有關(guān)此新檢查的其他上下文,請(qǐng)參閱#56040。
整頁(yè)緩存
這項(xiàng)新檢查確定站點(diǎn)是否正在使用整頁(yè)緩存解決方案以及響應(yīng)時(shí)間是否可以接受。
它還添加了一些過濾器,旨在讓托管公司自定義響應(yīng)閾值并添加自己的緩存標(biāo)頭以進(jìn)??行檢測(cè)。
新增的 site_status_good_response_time_threshold過濾器允許修改 600 毫秒的當(dāng)前閾值。低于此值的所有內(nèi)容都將被認(rèn)為是可以接受的。
/**
* Filter the response time threshold
*/
add_filter( 'site_status_good_response_time_threshold', function() {
return 200;
} );
可以通過site_status_page_cache_supported_cache_headers過濾器添加其他自定義緩存標(biāo)頭(以及可選的驗(yàn)證回調(diào))。
/**
* Filter the page cache supported cache headers
* $cache_headers contains List of client caching headers and their (optional) verification callbacks.
*/
add_filter( 'site_status_page_cache_supported_cache_headers', function( $cache_headers ) {
// Add new header to the existing list.
$cache_headers['cf-cache-status'] = static function ( $header_value ) {
return false !== strpos( strtolower( $header_value ), 'hit' );
};
return $cache_headers;
});
有關(guān)此新檢查的其他上下文,請(qǐng)參閱#56041。




