Cache API: Add wp_cache_get_multiple() to core functions.

* `update_object_term_cache`
* `update_meta_cache`
* `_get_non_cached_ids`

See [47938].

Fixes #50352.

Props spacedmonkey, tillkruss, lukecavanagh. 



git-svn-id: https://develop.svn.wordpress.org/trunk@48055 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jake Spurlock 2020-06-16 06:28:57 +00:00
parent acf0f67a43
commit def933ced7
3 changed files with 14 additions and 12 deletions

View File

@ -6359,10 +6359,11 @@ function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pr
* @return int[] Array of IDs not present in the cache. * @return int[] Array of IDs not present in the cache.
*/ */
function _get_non_cached_ids( $object_ids, $cache_key ) { function _get_non_cached_ids( $object_ids, $cache_key ) {
$clean = array(); $clean = array();
foreach ( $object_ids as $id ) { $cache_values = wp_cache_get_multiple( $object_ids, $cache_key );
foreach ( $cache_values as $id => $cache_value ) {
$id = (int) $id; $id = (int) $id;
if ( ! wp_cache_get( $id, $cache_key ) ) { if ( ! $cache_value ) {
$clean[] = $id; $clean[] = $id;
} }
} }

View File

@ -926,11 +926,11 @@ function update_meta_cache( $meta_type, $object_ids ) {
return (bool) $check; return (bool) $check;
} }
$cache_key = $meta_type . '_meta'; $cache_key = $meta_type . '_meta';
$ids = array(); $ids = array();
$cache = array(); $cache = array();
foreach ( $object_ids as $id ) { $cache_values = wp_cache_get_multiple( $object_ids, $cache_key );
$cached_object = wp_cache_get( $id, $cache_key ); foreach ( $cache_values as $id => $cached_object ) {
if ( false === $cached_object ) { if ( false === $cached_object ) {
$ids[] = $id; $ids[] = $id;
} else { } else {

View File

@ -3410,10 +3410,11 @@ function update_object_term_cache( $object_ids, $object_type ) {
$taxonomies = get_object_taxonomies( $object_type ); $taxonomies = get_object_taxonomies( $object_type );
$ids = array(); $ids = array();
foreach ( (array) $object_ids as $id ) { foreach ( $taxonomies as $taxonomy ) {
foreach ( $taxonomies as $taxonomy ) { $cache_values = wp_cache_get_multiple( (array) $object_ids, "{$taxonomy}_relationships" );
if ( false === wp_cache_get( $id, "{$taxonomy}_relationships" ) ) { foreach ( $cache_values as $key => $value ) {
$ids[] = $id; if ( false === $value ) {
$ids[] = $key;
break; break;
} }
} }