Make WordPress Core

Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#54574 closed enhancement (fixed)

Add wp_cache_*_multiple function

Reported by: spacedmonkey's profile spacedmonkey Owned by: spacedmonkey's profile spacedmonkey
Milestone: 6.0 Priority: normal
Severity: normal Version:
Component: Cache API Keywords: has-patch has-unit-tests needs-docs has-dev-note
Focuses: performance Cc:

Description

The wp_cache_get_multiple function was added in #20875. This allow for multiple cache keys be collected in one request. To complete the api, we should add the full CRUD functions. So

  • wp_cache_add_multiple
  • wp_cache_delete_multiple
  • wp_cache_update_multiple

In core these would just be wrapper for core functions to allow multiple keys to passed in one function call. But would allow object cache plugin developers to implement them if their backend support it.

Change History (23)

#1 @tillkruess
3 years ago

One of the engineers at Pagely was just asking me about batch API methods for cache operations, so 👍

#2 @spacedmonkey
3 years ago

One the major things to need to decide to function signature. Here are some function signatures to consider.

function wp_cache_multiple_set( array $keys, array $values, array $groups )
function wp_cache_multiple_set( array $data )
$data = array( array( 'key' => 'test', 'value' => 'tool', 'group' => 'test'));
function wp_cache_multiple_set( array $key_value_pair, $group )


#3 follow-up: @spacedmonkey
3 years ago

These functions can be used in the following places.

  • update_meta_cache
  • update_post_cache
  • update_term_cache
  • clean_object_term_cache
  • clean_term_cache
  • wp_delete_post

This ticket was mentioned in PR #2018 on WordPress/wordpress-develop by spacedmonkey.


3 years ago
#4

  • Keywords has-patch added; needs-patch removed

#5 in reply to: ↑ 3 @adamsilverstein
2 years ago

This brings up my question: can we leverage these new functions in core already?

Is the plan to update the existing cache functions to accept multiple keys? Should these new functions be "private" or internal (start with _)?

Replying to spacedmonkey:

These functions can be used in the following places.

  • update_meta_cache
  • update_post_cache
  • update_term_cache
  • clean_object_term_cache
  • clean_term_cache
  • wp_delete_post

#6 @spacedmonkey
2 years ago

  • Keywords has-unit-tests added
  • Milestone changed from Awaiting Review to 6.0
  • Owner set to spacedmonkey
  • Status changed from new to assigned

#7 @spacedmonkey
2 years ago

Is the plan to update the existing cache functions to accept multiple keys? Should these new functions be "private" or internal (start with _)?

Good flag @adamsilverstein and YES! I have created a follow on ticket at #55029

tillkruss commented on PR #2018:


2 years ago
#8

@spacedmonkey This looks great. I've got one thought, what about atomicity?

Should we be adding an optional parameter to indicate that we'd want the call to be atomic? Whether the cache implementation supports or is able to, it is up to it.

tillkruss commented on PR #2018:


2 years ago
#9

@spacedmonkey This looks great. I've got one thought, what about atomicity?

Should we be adding an optional parameter to indicate that we'd want the call to be atomic? Whether the cache implementation supports or is able to, it is up to it.

spacedmonkey commented on PR #2018:


2 years ago
#10

CC @mitogh

#11 @spacedmonkey
2 years ago

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

In 52700:

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.

spacedmonkey commented on PR #2018:


2 years ago
#12

Merged

#13 @spacedmonkey
2 years ago

This PR is ready for re-review.

#14 @adamsilverstein
2 years ago

This PR is ready for re-review.

This comment is for https://core.trac.wordpress.org/ticket/55029, right?

#15 @SergeyBiryukov
2 years ago

In 52702:

Tests: Remove some extra wp_cache_set() calls from wp_cache_set_multiple() test.

These appear to be a copy/paste from the wp_cache_get_multiple() test and are not required here.

Follow-up to [47938], [52700].

See #54574.

#16 @SergeyBiryukov
2 years ago

In 52703:

Docs: Update DocBlocks for some object cache functions per the documentation standards.

Follow-up to [47060], [47938], [47944], [52700].

See #54729, #54574.

#17 @SergeyBiryukov
2 years ago

In 52706:

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.

#18 @SergeyBiryukov
2 years ago

In 52708:

Docs: Improve @return tags for wp_cache_*_multiple() functions:

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

This aims to provide more details about the returned value types.

Follow-up to [52700], [52702], [52703].

See #54729, #54574.

This ticket was mentioned in Slack in #hosting-community by javier. View the logs.


2 years ago

This ticket was mentioned in Slack in #hosting-community by amykamala. View the logs.


2 years ago

#21 @milana_cap
2 years ago

  • Keywords needs-dev-note needs-docs added

#22 @spacedmonkey
2 years ago

Dev note ready for review.

Note: See TracTickets for help on using tickets.