Tests: Consistently sanitize expiration in the test suite's Memcached implementation.

In a previous commit, the `::sanitize_expiration()` call in the `::add()` method was moved closer to where the value is used.

This commit does the same for the other methods:
* `::cas()`
* `::replace()`
* `::set()`
* `::setMulti()`

Follow-up to [40561], [55577].

See #57841, #57963.

git-svn-id: https://develop.svn.wordpress.org/trunk@55581 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2023-03-22 09:25:32 +00:00
parent d0f1816c36
commit 464ad20218

View File

@ -1181,7 +1181,6 @@ class WP_Object_Cache {
*/
public function cas( $cas_token, $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) {
$derived_key = $this->buildKey( $key, $group );
$expiration = $this->sanitize_expiration( $expiration );
/**
* If group is a non-Memcached group, save to runtime cache, not Memcached. Note
@ -1193,6 +1192,8 @@ class WP_Object_Cache {
return true;
}
$expiration = $this->sanitize_expiration( $expiration );
// Save to Memcached.
if ( $by_key ) {
$result = $this->m->casByKey( $cas_token, $server_key, $derived_key, $value, $expiration );
@ -1906,7 +1907,6 @@ class WP_Object_Cache {
*/
public function replace( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) {
$derived_key = $this->buildKey( $key, $group );
$expiration = $this->sanitize_expiration( $expiration );
// If group is a non-Memcached group, save to runtime cache, not Memcached.
if ( in_array( $group, $this->no_mc_groups, true ) ) {
@ -1920,6 +1920,8 @@ class WP_Object_Cache {
return true;
}
$expiration = $this->sanitize_expiration( $expiration );
// Save to Memcached.
if ( $by_key ) {
$result = $this->m->replaceByKey( $server_key, $derived_key, $value, $expiration );
@ -1971,7 +1973,6 @@ class WP_Object_Cache {
*/
public function set( $key, $value, $group = 'default', $expiration = 0, $server_key = '', $by_key = false ) {
$derived_key = $this->buildKey( $key, $group );
$expiration = $this->sanitize_expiration( $expiration );
// If group is a non-Memcached group, save to runtime cache, not Memcached.
if ( in_array( $group, $this->no_mc_groups, true ) ) {
@ -1979,6 +1980,8 @@ class WP_Object_Cache {
return true;
}
$expiration = $this->sanitize_expiration( $expiration );
// Save to Memcached.
if ( $by_key ) {
$result = $this->m->setByKey( $server_key, $derived_key, $value, $expiration );
@ -2033,7 +2036,6 @@ class WP_Object_Cache {
public function setMulti( $items, $groups = 'default', $expiration = 0, $server_key = '', $by_key = false ) {
// Build final keys and replace $items keys with the new keys.
$derived_keys = $this->buildKeys( array_keys( $items ), $groups );
$expiration = $this->sanitize_expiration( $expiration );
$derived_items = array_combine( $derived_keys, $items );
// Do not add to memcached if in no_mc_groups.
@ -2049,6 +2051,8 @@ class WP_Object_Cache {
}
}
$expiration = $this->sanitize_expiration( $expiration );
// Save to memcached.
if ( $by_key ) {
$result = $this->m->setMultiByKey( $server_key, $derived_items, $expiration );