Make WordPress Core

Opened 2 years ago

Closed 18 months ago

#54864 closed enhancement (fixed)

Update the object-cache.php in phpunit fixture to support wp_cache_get_multiple

Reported by: spacedmonkey's profile spacedmonkey Owned by: spacedmonkey's profile spacedmonkey
Milestone: 6.2 Priority: normal
Severity: normal Version: 4.8
Component: Build/Test Tools Keywords: has-patch has-unit-tests
Focuses: Cc:

Description (last modified by spacedmonkey)

The object-cache file used in tests/phpunit/includes/object-cache.php is used in PHPUnit tests. In this file, there are references to wp_cache_get_multi. However, these functions do not exist in core. In WordPress 5.5, the wp_cache_get_multiple function was added. This function should be implemented in the object-cache.php file.

Change History (21)

#1 @spacedmonkey
2 years ago

  • Description modified (diff)

#2 @spacedmonkey
2 years ago

In [52700] wp_cache_add_multiple, wp_cache_set_multiple and wp_cache_delete_multiple were added. While working on this patch, we should also add these functions as well.

This ticket was mentioned in PR #2648 on WordPress/wordpress-develop by petitphp.

2 years ago

  • Keywords has-patch has-unit-tests added; needs-patch removed

Add functions wp_cache_get_multiple, wp_cache_add_multiple, wp_cache_set_multiple, wp_cache_delete_multiple
in tests/phpunit/includes/object-cache.php

Trac ticket:

tillkruss commented on PR #2648:

23 months ago

@petitphp the memcached tests are failing.

petitphp commented on PR #2648:

23 months ago

I'll take a look.

petitphp commented on PR #2648:

20 months ago

@tillkruss I've updated the PR to fix failing tests.

tillkruss commented on PR #2648:

20 months ago

I've updated the PR to fix failing tests.

LGTM, let me see if @felixarntz or @SergeyBiryukov can merge this?

SergeyBiryukov commented on PR #2648:

20 months ago

Thanks for the PR! Looks good to me.

It appears that the file was originally copied in r40561 / #40619 from tollmanz/wordpress-pecl-memcached-object-cache, which is now maintained at humanmade/wordpress-pecl-memcached-object-cache and has a note on the plugin status:

Since this plugin was last updated, WordPress has introduced a variety of caching API improvements such as wp_cache_get_multiple(). This plugin has not been updated to take advantage of these new functions, because Human Made now uses Redis for our own caching backend. It should still work, but it will not be as efficient as it could be given the functionality in the latest versions of WordPress.

The file already has wp_cache_get_multi() and wp_cache_set_multi(), but the signatures don't exactly match the core functions:

function wp_cache_get_multi( $keys, $groups = '', &$cas_tokens = null, $flags = null )
function wp_cache_get_multiple( $keys, $group = '', $force = false )

function wp_cache_set_multi( $items, $groups = '', $expiration = 0 )
function wp_cache_set_multiple( array $data, $group = '', $expire = 0 )

So I think it makes sense to introduce the variants of these functions that WordPress core uses.

I've made a few minor adjustments for consistency:

  • Placing the new functions directly after the related functions.
  • Using camelCase for the method names to match other methods in the class.
  • Renaming some parameters: $data to $items and $expire to $expiration to match other functions.

#9 @SergeyBiryukov
20 months ago

  • Milestone changed from Awaiting Review to 6.1

#10 @SergeyBiryukov
20 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 54423:

Tests: Add wp_cache_*_multiple() functions to Memcached implementation used in the test suite.

Since this object cache implementation was added, WordPress has introduced a variety of caching API improvements:

  • wp_cache_add_multiple()
  • wp_cache_set_multiple()
  • wp_cache_get_multiple()
  • wp_cache_delete_multiple()

Although WordPress core provides a compatibility layer if these functions are missing from third-party object caches, this commit updates the Memcached object cache used in the test suite to implement these new functions directly.

Follow-up to [40561], [47938], [47944], [52700], [52703], [52706], [52708].

Props petitphp, spacedmonkey, tillkruss, SergeyBiryukov.
Fixes #54864.

SergeyBiryukov commented on PR #2648:

20 months ago

Merged in r54423.

#12 @spacedmonkey
19 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

#14 @spacedmonkey
19 months ago

@SergeyBiryukov I have reopenned- to full implement get_multiple, that gets multiple keys in a single memcache call.

#15 @SergeyBiryukov
19 months ago

  • Milestone changed from 6.1 to 6.2

@spacedmonkey commented on PR #3548:

19 months ago

Correctly implementing this function and priming multiple in a single request, speeds up the unit tests. From 5.28 minutes to 4 minutes.

#17 @spacedmonkey
18 months ago

@SergeyBiryukov Chance of a review. The PR is pretty simple.

#18 @spacedmonkey
18 months ago

  • Owner changed from SergeyBiryukov to spacedmonkey
  • Status changed from reopened to assigned

#19 @spacedmonkey
18 months ago

In 54942:

Tests: Change the wp_cache_get_multiple function to get cache keys in a single request.

Follow up from [54423].

Change the wp_cache_get_multiple function to call the getMulti method in the object cache object, to get cache keys in a single call to memcache. This speeds up test by loading caches faster.

Props spacedmonkey, SergeyBiryukov.
See #54864.

@SergeyBiryukov commented on PR #3548:

18 months ago

This was committed in r54942.

#21 @SergeyBiryukov
18 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

I think this was fixed in [54423] and [54942].

Note: See TracTickets for help on using tickets.