Cache API: Introduce new queries cache groups.

Give developers more control over how query caches are handled within an object caches. Now all caches that cache the result of a query, are cached in a group that is suffixed with -queries. Developers can use these groups, to add custom cache invalidation rules or to make them none persistent.

Props spacedmonkey, owi, tillkruess, skithund, peterwilsoncc, flixos90, sergeybiryukov, mukesh27.
Fixes #57625.

git-svn-id: https://develop.svn.wordpress.org/trunk@55526 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonny Harris
2023-03-10 16:27:23 +00:00
parent 4af22e53d7
commit 82cd434194
13 changed files with 52 additions and 52 deletions
+6 -6
View File
@@ -5675,7 +5675,7 @@ function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) {
$hash = md5( $page_path . serialize( $post_type ) );
$cache_key = "get_page_by_path:$hash:$last_changed";
$cached = wp_cache_get( $cache_key, 'posts' );
$cached = wp_cache_get( $cache_key, 'post-queries' );
if ( false !== $cached ) {
// Special case: '0' is a bad `$page_path`.
if ( '0' === $cached || 0 === $cached ) {
@@ -5742,7 +5742,7 @@ function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) {
}
// We cache misses as well as hits.
wp_cache_set( $cache_key, $foundid, 'posts' );
wp_cache_set( $cache_key, $foundid, 'post-queries' );
if ( $foundid ) {
return get_post( $foundid, $output );
@@ -5983,7 +5983,7 @@ function get_pages( $args = array() ) {
$last_changed = wp_cache_get_last_changed( 'posts' );
$cache_key = "get_pages:$key:$last_changed";
$cache = wp_cache_get( $cache_key, 'posts' );
$cache = wp_cache_get( $cache_key, 'post-queries' );
if ( false !== $cache ) {
_prime_post_caches( $cache, false, false );
@@ -6148,7 +6148,7 @@ function get_pages( $args = array() ) {
$pages = $wpdb->get_results( $query );
if ( empty( $pages ) ) {
wp_cache_set( $cache_key, array(), 'posts' );
wp_cache_set( $cache_key, array(), 'post-queries' );
/** This filter is documented in wp-includes/post.php */
$pages = apply_filters( 'get_pages', array(), $parsed_args );
@@ -6191,7 +6191,7 @@ function get_pages( $args = array() ) {
$page_structure[] = $page->ID;
}
wp_cache_set( $cache_key, $page_structure, 'posts' );
wp_cache_set( $cache_key, $page_structure, 'post-queries' );
// Convert to WP_Post instances.
$pages = array_map( 'get_post', $pages );
@@ -7355,7 +7355,7 @@ function clean_post_cache( $post ) {
do_action( 'clean_page_cache', $post->ID );
}
wp_cache_set( 'last_changed', microtime(), 'posts' );
wp_cache_set_posts_last_changed();
}
/**