Make WordPress Core


Ignore:
Timestamp:
06/09/2020 07:45:27 PM (6 years ago)
Author:
whyisjake
Message:

Cache API: Introduce wp_cache_get_multi().

Many caching backend have support for multiple gets in a single request. This brings that support to core, with a compatability fallback that will loop over requests if needed.

Fixes: #20875.
Props: nacin, tollmanz, wonderboymusic, ryan, jeremyfelt, spacedmonkey, boonebgorges, dd32, rmccue, ocean90, jipmoors, johnjamesjacoby, tillkruess, donmhico, davidbaumwald, SergeyBiryukov, whyisjake.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-object-cache.php

    r47637 r47938  
    304304
    305305        /**
     306         * Retrieves multiple values from the cache.
     307         *
     308         * @since  5.5.0
     309         *
     310         * @param array $keys        Array of keys to fetch.
     311         * @param bool  $force       Optional. Unused. Whether to force a refetch rather than relying on the local
     312         *                           cache. Default false.
     313         *
     314         * @return array Array of values organized into groups.
     315         */
     316        public function get_multiple( $keys, $group = 'default', $force = false ) {
     317                $values = array();
     318
     319                foreach ( $keys as $key ) {
     320                        $values[ $key ] = $this->get( $key, $group, $force );
     321                }
     322
     323                return $values;
     324        }
     325
     326        /**
    306327         * Increments numeric cache item's value.
    307328         *
Note: See TracChangeset for help on using the changeset viewer.