Opened 13 months ago
Last modified 2 months ago
#20875 new enhancement
Introduce wp_cache_get_multi()
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Cache | Version: | |
| Severity: | normal | Keywords: | has-patch 3.7-early |
| Cc: | zack@…, tollmanz@…, aaroncampbell |
Description
Both options (see #10274) and themes (see #20103) could benefit from a cache backend that implements get_multi(). For options, this means we can use individual keys. For both themes and options, we'd be able to make fast multiple gets.
Both APC and Memcached (but not Memcache) implement multiple-get. A fallback would be looping over get().
Separately, as this would be a new function we use in core, we probably need to start doing some kind of versioning for drop-ins like db.php and object-cache.php.
Attachments (3)
Change History (10)
comment:3
wonderboymusic
— 8 months ago
I cribbed the Memcache code to implement it here: http://wordpress.org/extend/plugins/memcached-redux/
comment:4
aaroncampbell
— 5 months ago
- Cc aaroncampbell added
comment:5
ryan
— 5 months ago
For back compat reasons, the API here should handle the call signature used in the memcached plugin. Looks like the patch might already handle that. http://plugins.svn.wordpress.org/memcached/trunk/object-cache.php
wonderboymusic
— 4 months ago
comment:6
wonderboymusic
— 4 months ago
- Milestone changed from Awaiting Review to 3.6
I squeezed the code into new code - I don't think the return value needs to be associative and bucketed. I think a standard use-case for get_multi in action is:
list( $one, $two, $three ) = wp_cache_get_multi( array( 'one', 'two', 'three' ), 'numbers' );
I imagine that there is a lot to be discussed about how this should work, but I am adding a patch to move things along. I added a first attempt at a get_multi function with this patch. Additionally, I have written unit tests and uploaded them here (would appreciate some direction on if these should also be added to the unit test trac and what's the right way to do that organizationally).
This get_multi function uses the get function to retrieve values from the $cache var. An array of keys and groups are sent to the function. The function attempts to figure out the relationship between the $keys and $groups values. The logic is:
Values are returned as an array with top level keys being groups. The second level keys are the cache key values. This should match the organization within the $cache var itself.
A number of different scenarios have been tested in the unit tests and this seems to be working well for the assumptions I have laid out.