Make WordPress Core

Changeset 55577


Ignore:
Timestamp:
03/21/2023 05:00:21 PM (20 months ago)
Author:
spacedmonkey
Message:

Build/Test Tools: Fix issue with add method in object-cache.php.

In the object-cache.php file used for unit tests, the add method did not work as expected. Other object cache plugins and core, have a check to see if the key exists in memory before writing it. Without this check, it used to write unnecessarily to the cache.

Props spacedmonkey, SergeyBiryukov.
Fixes #57963.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/object-cache.php

    r54942 r55577  
    978978
    979979        $derived_key = $this->buildKey( $key, $group );
    980         $expiration  = $this->sanitize_expiration( $expiration );
     980
     981        // Add does not set the value if the key exists; mimic that here.
     982        if ( isset( $this->cache[ $derived_key ] ) ) {
     983            return false;
     984        }
    981985
    982986        // If group is a non-Memcached group, save to runtime cache, not Memcached.
    983987        if ( in_array( $group, $this->no_mc_groups, true ) ) {
    984988
    985             // Add does not set the value if the key exists; mimic that here.
    986             if ( isset( $this->cache[ $derived_key ] ) ) {
    987                 return false;
    988             }
    989 
    990989            $this->add_to_internal_cache( $derived_key, $value );
    991990
    992991            return true;
    993992        }
     993
     994        $expiration = $this->sanitize_expiration( $expiration );
    994995
    995996        // Save to Memcached.
Note: See TracChangeset for help on using the changeset viewer.