谷歌adwords广告推广跨境万元户 - 用户体验最好的品牌

WordPress 6.1重大升级:WP_Query性能优化实现0SQL查询 WordPress 6.1 Major Update: WP_Query Performance Optimization Achieves 0SQL Q

WordPress 6.1重大升级:WP_Query性能优化实现0SQL查询

WordPress 6.1重大升级:WP_Query性能优化实现0SQL查询

WordPress 6.1 Major Update: WP_Query Performance Optimization Achieves 0SQL Queries

WP_Query的核心改进

Core Improvements to WP_Query

WP_Query是WordPress中最重要的类,几乎每个页面都使用它来获取文章内容。但其最大问题是直接查询数据库且结果未被缓存。

WP_Query is the most important class in WordPress, used by nearly every page to fetch posts. However, its biggest issue was querying the database directly without caching results.

WordPress 6.1对WP_Query类进行了重大改进:

WordPress 6.1 brings significant improvements to the WP_Query class:

1. 实现了SQL查询缓存机制,相同查询将直接从缓存加载

1. Implements SQL query caching mechanism, identical queries will load from cache

2. 对于使用Memcached等持久化对象缓存的站点,效果尤为显著

2. Particularly effective for sites using persistent object caching like Memcached

3. 即使没有内存缓存,同一页面内的相同查询也不会重复执行

3. Even without memory caching, identical queries within the same page won't repeat

开发者注意事项

Developer Considerations

建议开发者使用WordPress提供的文章操作函数(如wp_insert_post),这些函数会自动清理缓存。

Developers should use WordPress post operation functions (like wp_insert_post) which automatically clear cache.

如果直接使用SQL语句更新数据库,务必调用clean_post_cache()清理缓存。

When using direct SQL queries, be sure to call clean_post_cache().

缓存控制方法

Cache Control Methods

禁用缓存方法(仅在特殊情况下使用):

Disabling cache (use only in special cases):

 $query = new WP_Query(array( 'posts_per_page' => 50, 'cache_results' => false ));

或通过filter全局禁用:

Or disable globally via filter:

 add_action('parse_query', function($wp_query){ $wp_query->query_vars['cache_results'] = false; });

性能优化亮点

Performance Highlights

1. 新增update_post_author_caches函数,一次性加载所有作者信息

1. New update_post_author_caches function loads all author info at once

2. 新增update_menu_item_cache函数,优化菜单项数据加载

2. New update_menu_item_cache function optimizes menu item data loading

3. get_page_by_title现在也使用WP_Query,享受缓存优势

3. get_page_by_title now uses WP_Query and benefits from caching

这些改进将显著提升WordPress站点的性能表现,特别是对于内容丰富的网站。

These improvements will significantly enhance WordPress site performance, especially for content-rich websites.

WordPress 6.1重大升级:WP_Query性能优化实现0SQL查询