外贸独立站的底层设计密码WordPress 成品站SaaS建站
当前位置:首页>WordPress资讯>WordPress 6.1 的站点健康检查新增缓存检查

WordPress 6.1 的站点健康检查新增缓存检查

作为 WordPress 6.1 版本的一部分,性能团队添加了两项站点健康检查(持久对象缓存和页面缓存)。这些检查之前在Performance Lab 插件中进行了测试。您可以在原始提案中阅读更多关于它们的信息。

这两项检查都将仅在生产环境中运行。

持久对象缓存

这项新检查确定站点是否使用持久对象缓存,并在对站点有意义时推荐它。它还链接到为检查创建的支持资源。

已包含一些过滤器,旨在让托管服务提供商提供有关其环境的更具体的步骤。

管理员可以使用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过滤器自定义注释以推荐他们首选的对象缓存解决方案。

/**
 * 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 认为使用持久对象缓存有益的阈值。

/**
 * 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是一个短路(short-circuit)过滤器,它允许使用完全自定义的逻辑来确定持久对象缓存是否对站点有意义。

/**
 * Opt in for suggesting the persistent object cache
 */
add_filter( 'site_status_should_suggest_persistent_object_cache', '__return_true' );

有关此新检查的其他上下文,请参阅#56040

整页缓存

这项新检查确定站点是否正在使用整页缓存解决方案以及响应时间是否可以接受。

它还添加了一些过滤器,旨在让托管公司自定义响应阈值并添加自己的缓存标头以进​​行检测。

新增的 site_status_good_response_time_threshold过滤器允许修改 600 毫秒的当前阈值。低于此值的所有内容都将被认为是可以接受的。

/**
 * Filter the response time threshold
 */
add_filter( 'site_status_good_response_time_threshold', function() {
    return 200;
} );

可以通过site_status_page_cache_supported_cache_headers过滤器添加其他自定义缓存标头(以及可选的验证回调)。

/**
 * 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;
});

有关此新检查的其他上下文,请参阅#56041

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
欢迎关注WordPress大学公众号 WPDAXUE
WordPress资讯

WordPress 6.1 新增的默认主题2023功能特色详解

2022-10-6 17:39:25

WordPress开发WordPress资讯

WordPress 6.1 引入了填充、边距和块间隙的预设值

2022-10-9 10:10:50

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索