WordPress 6.1 新增缓存检查功能详解

WordPress 6.1 版本中,性能团队引入了两项重要的站点健康检查功能——持久对象缓存和页面缓存,旨在帮助用户更全面地评估网站性能。这些检查此前已在Performance Lab插件中进行过充分测试,确保其可靠性和实用性。更多详细信息可参考原始提案文档。

这两项检查将专门在生产环境中运行,以确保评估结果的准确性。下面分别介绍这两项新功能的具体内容。

### 持久对象缓存检查

持久对象缓存检查旨在评估网站是否有效利用了持久对象缓存技术,并在适用情况下提供专业推荐。该检查不仅会分析当前配置,还会链接到专门的支持资源,为用户提供更直观的操作指南。

为了适应不同托管环境的特性,开发团队已内置多项过滤器,允许托管服务提供商根据自身环境提供更精准的操作步骤。管理员可以通过`site_status_persistent_object_cache_url`过滤器自定义推荐指南的链接,例如:

“`php
add_filter( ‘site_status_persistent_object_cache_url’, function() {
return ‘https://awesomewphosting.com/optimization/persistent-object-cache’;
} );
“`

此外,`site_status_persistent_object_cache_notes`过滤器允许管理员添加自定义注释,推荐特定的对象缓存解决方案:

“`php
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判定使用持久对象缓存的阈值,例如:

“`php
add_filter( ‘site_status_persistent_object_cache_thresholds’, function( $thresholds ) {
return array(
‘alloptions_count’ => 600,
‘alloptions_bytes’ => 200000,
‘comments_count’ => 2000,
‘options_count’ => 2000,
‘posts_count’ => 2000,
‘terms_count’ => 2000,
‘users_count’ => 2000,
);
} );
“`

WordPress 6.1 新增缓存检查功能详解

若需完全自定义建议逻辑,`site_status_should_suggest_persistent_object_cache`短路过滤器提供了灵活的解决方案:

“`php
add_filter( ‘site_status_should_suggest_persistent_object_cache’, ‘__return_true’ );
“`

更多技术细节可参考GitHub问题#56040。

### 整页缓存检查

整页缓存检查则专注于评估网站是否采用了整页缓存方案,并检测其响应时间是否达到可接受标准。该功能同样配备了多项过滤器,便于托管公司根据实际需求调整检测参数。

通过`site_status_good_response_time_threshold`过滤器,管理员可修改默认的600毫秒响应时间阈值,例如将标准调整为200毫秒:

“`php
add_filter( ‘site_status_good_response_time_threshold’, function() {
return 200;
} );
“`

此外,`site_status_page_cache_supported_cache_headers`过滤器允许添加自定义缓存标头,增强检测的全面性:

“`php
add_filter( ‘site_status_page_cache_supported_cache_headers’, function( $cache_headers ) {
$cache_headers[‘cf-cache-status’] = static function ( $header_value ) {
return false !== strpos( strtolower( $header_value ), ‘hit’ );
};
return $cache_headers;
} );
“`

这一创新功能将为网站性能优化提供更精准的指导,具体实现细节可查阅GitHub问题#56041。

通过这些新增的健康检查功能,WordPress 6.1进一步提升了网站性能评估的智能化水平,为用户和托管服务商提供了更强大的工具支持。

文章网址:https://www.wpbull.com/news/1992.html