Make WordPress Core


Ignore:
Timestamp:
02/11/2022 12:50:54 PM (3 years ago)
Author:
spacedmonkey
Message:

Cache: Add wp_cache_*_multiple functions.

Add new caching functions named wp_cache_add_multiple, wp_cache_set_multiple and wp_cache_delete_multiple. All of these functions allow for an array of data to be passed, so that multiple cache objects can be created / edited / deleted in a single function call. This follows on from [47938] where the wp_cache_get_multiple function was introduced and allowed for multiple cache objects to be received in one call.

Props: spacedmonkey, tillkruess, adamsilverstein, flixos90, mitogh, pbearne.
Fixes: #54574.

File:
1 edited

Legend:

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

    r49693 r52700  
    146146}
    147147
     148
     149/**
     150 * Delete multiple values from the cache in one call.
     151 *
     152 * @since 6.0.0
     153 *
     154 * @see WP_Object_Cache::delete_multiple()
     155 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
     156 *
     157 * @param array  $keys  Array of keys under which the cache to deleted.
     158 * @param string $group Optional. Where the cache contents are grouped. Default empty.
     159 * @return array Array of return values organized into groups.
     160 */
     161function wp_cache_delete_multiple( array $keys, $group = '' ) {
     162    global $wp_object_cache;
     163
     164    return $wp_object_cache->delete_multiple( $keys, $group );
     165}
     166
     167/**
     168 * Add multiple values to the cache in one call.
     169 *
     170 * @since 6.0.0
     171 *
     172 * @see WP_Object_Cache::add_multiple()
     173 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
     174 *
     175 * @param array  $data  Array of key and value to be set.
     176 * @param string $group Optional. Where the cache contents are grouped. Default empty.
     177 * @param int    $expire Optional. When to expire the cache contents, in seconds.
     178 *                           Default 0 (no expiration).
     179 * @return array Array of return values.
     180 */
     181function wp_cache_add_multiple( array $data, $group = '', $expire = 0 ) {
     182    global $wp_object_cache;
     183
     184    return $wp_object_cache->add_multiple( $data, $group, $expire );
     185}
     186
     187/**
     188 * Set multiple values to the cache in one call.
     189 *
     190 * @since 6.0.0
     191 *
     192 * @see WP_Object_Cache::set_multiple()
     193 * @global WP_Object_Cache $wp_object_cache Object cache global instance.
     194 *
     195 * @param array  $data  Array of key and value to be set.
     196 * @param string $group Optional. Where the cache contents are grouped. Default empty.
     197 * @param int    $expire Optional. When to expire the cache contents, in seconds.
     198 *                           Default 0 (no expiration).
     199 * @return array Array of return values.
     200 */
     201function wp_cache_set_multiple( array $data, $group = '', $expire = 0 ) {
     202    global $wp_object_cache;
     203
     204    return $wp_object_cache->set_multiple( $data, $group, $expire );
     205}
     206
    148207/**
    149208 * Increment numeric cache item's value
Note: See TracChangeset for help on using the changeset viewer.