Make WordPress Core


Ignore:
Timestamp:
02/11/2022 06:47:38 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Cache API: Reorder object cache functions and methods for consistency.

The original order was alphabetical, which became less obvious as newer functions got added, resulting in a somewhat random order.

This commits aims to organize the functions and related WP_Object_Cache methods in a more predictable order:

  • wp_cache_init()
  • wp_cache_add()
  • wp_cache_add_multiple()
  • wp_cache_replace()
  • wp_cache_set()
  • wp_cache_set_multiple()
  • wp_cache_get()
  • wp_cache_get_multiple()
  • wp_cache_delete()
  • wp_cache_delete_multiple()
  • wp_cache_incr()
  • wp_cache_decr()
  • wp_cache_flush()
  • wp_cache_close()
  • wp_cache_add_global_groups()
  • wp_cache_add_non_persistent_groups()
  • wp_cache_switch_to_blog()
  • wp_cache_reset()

Follow-up to [3011], [6543], [7986], [13066], [18580], [21403], [47938], [52700], [52703-52705].

See #54728, #54574.

File:
1 edited

Legend:

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

    r52703 r52706  
    88 * @subpackage Cache
    99 */
    10 
    11 if ( ! function_exists( 'wp_cache_get_multiple' ) ) :
    12         /**
    13          * Retrieves multiple values from the cache in one call.
    14          *
    15          * Compat function to mimic wp_cache_get_multiple().
    16          *
    17          * @ignore
    18          * @since 5.5.0
    19          *
    20          * @see wp_cache_get_multiple()
    21          *
    22          * @param array  $keys  Array of keys under which the cache contents are stored.
    23          * @param string $group Optional. Where the cache contents are grouped. Default empty.
    24          * @param bool   $force Optional. Whether to force an update of the local cache
    25          *                      from the persistent cache. Default false.
    26          * @return array Array of values organized into groups.
    27          */
    28         function wp_cache_get_multiple( $keys, $group = '', $force = false ) {
    29                 $values = array();
    30 
    31                 foreach ( $keys as $key ) {
    32                         $values[ $key ] = wp_cache_get( $key, $group, $force );
    33                 }
    34 
    35                 return $values;
    36         }
    37 endif;
    38 
    39 if ( ! function_exists( 'wp_cache_delete_multiple' ) ) :
    40         /**
    41          * Deletes multiple values from the cache in one call.
    42          *
    43          * Compat function to mimic wp_cache_delete_multiple().
    44          *
    45          * @ignore
    46          * @since 6.0.0
    47          *
    48          * @see wp_cache_delete_multiple()
    49          *
    50          * @param array  $keys  Array of keys under which the cache to deleted.
    51          * @param string $group Optional. Where the cache contents are grouped. Default empty.
    52          * @return array Array of return values.
    53          */
    54         function wp_cache_delete_multiple( array $keys, $group = '' ) {
    55                 $values = array();
    56 
    57                 foreach ( $keys as $key ) {
    58                         $values[ $key ] = wp_cache_delete( $key, $group );
    59                 }
    60 
    61                 return $values;
    62         }
    63 endif;
    64 
    6510
    6611if ( ! function_exists( 'wp_cache_add_multiple' ) ) :
     
    12166        }
    12267endif;
     68
     69if ( ! function_exists( 'wp_cache_get_multiple' ) ) :
     70        /**
     71         * Retrieves multiple values from the cache in one call.
     72         *
     73         * Compat function to mimic wp_cache_get_multiple().
     74         *
     75         * @ignore
     76         * @since 5.5.0
     77         *
     78         * @see wp_cache_get_multiple()
     79         *
     80         * @param array  $keys  Array of keys under which the cache contents are stored.
     81         * @param string $group Optional. Where the cache contents are grouped. Default empty.
     82         * @param bool   $force Optional. Whether to force an update of the local cache
     83         *                      from the persistent cache. Default false.
     84         * @return array Array of values organized into groups.
     85         */
     86        function wp_cache_get_multiple( $keys, $group = '', $force = false ) {
     87                $values = array();
     88
     89                foreach ( $keys as $key ) {
     90                        $values[ $key ] = wp_cache_get( $key, $group, $force );
     91                }
     92
     93                return $values;
     94        }
     95endif;
     96
     97if ( ! function_exists( 'wp_cache_delete_multiple' ) ) :
     98        /**
     99         * Deletes multiple values from the cache in one call.
     100         *
     101         * Compat function to mimic wp_cache_delete_multiple().
     102         *
     103         * @ignore
     104         * @since 6.0.0
     105         *
     106         * @see wp_cache_delete_multiple()
     107         *
     108         * @param array  $keys  Array of keys under which the cache to deleted.
     109         * @param string $group Optional. Where the cache contents are grouped. Default empty.
     110         * @return array Array of return values.
     111         */
     112        function wp_cache_delete_multiple( array $keys, $group = '' ) {
     113                $values = array();
     114
     115                foreach ( $keys as $key ) {
     116                        $values[ $key ] = wp_cache_delete( $key, $group );
     117                }
     118
     119                return $values;
     120        }
     121endif;
Note: See TracChangeset for help on using the changeset viewer.