[wp-trac] [WordPress Trac] #20875: Introduce wp_cache_get_multi()

WordPress Trac noreply at wordpress.org
Sat May 28 04:37:40 UTC 2016


#20875: Introduce wp_cache_get_multi()
--------------------------------------------------+-----------------------
 Reporter:  nacin                                 |       Owner:
     Type:  enhancement                           |      Status:  reopened
 Priority:  normal                                |   Milestone:  4.6
Component:  Cache API                             |     Version:
 Severity:  normal                                |  Resolution:
 Keywords:  has-patch has-unit-tests 2nd-opinion  |     Focuses:
--------------------------------------------------+-----------------------
Changes (by boonebgorges):

 * keywords:  needs-patch needs-unit-tests => has-patch has-unit-tests 2nd-
     opinion
 * milestone:  Future Release => 4.6


Comment:

 A couple of patches, in the interest of moving this ticket along.

 [attachment:20875.3.diff] is a core patch that shows what the default
 `wp_cache_get_multi()` might look like. Instead of the `( $keys, $groups
 )` syntax suggested by @tollmanz, I've gone for the more straightforward
 multidimensional array:

 {{{
 $cached = wp_cache_get_multi( array(
     'cache_group_1' => array( 'foo', 'bar' ),
     'cache_group_2' => array( 'baz' ),
 ) );
 }}}

 This syntax is more verbose in many cases, but (a) it's more consistent
 and thus clearer, and (b) it better parallels the format of the array
 returned by the function. This format is what's expected by
 https://github.com/ericmann/Redis-Object-Cache/blob/master/object-
 cache.php#L546 and https://plugins.svn.wordpress.org/memcached/trunk
 /object-cache.php, but different from what's expected by
 https://github.com/mgmartel/memcached-redux/blob/master/object-
 cache.php#L256 and https://github.com/tollmanz/wordpress-pecl-memcached-
 object-cache/blob/master/object-cache.php#L1384 (the latter two expect
 @tollmanz's syntax, or some subset of it). We are going to have to break
 compatibility with something, so I'd suggest we choose the syntax we like
 the best. I prefer what's in my patch, but I don't feel strongly about it.

 [attachment:20875-example-usage.diff] is an example of how it'd be used in
 core. The example is from #36953. This is a particularly interesting
 example because it's fetching from lots of cache *groups* at the same
 time. (If we go forward with this ticket, I'd move the logic from this
 patch into `get_object_term_cache()` - the patch is for demonstration
 only.)

 [attachment:20875-implementation-apc.php] is a totally untested PoC patch
 for the APC drop-in.

 I haven't accounted for the `$force` or `$found` parameters that `get()`
 has. It's hard to deal with them without making the syntax even more
 convoluted. Worth noting that the Redis and Memcached plugins listed above
 also do not support these flags, for `get_multi()` *or* for `get()`.

 It's still #yolofriday where I live, so I'm putting this up for 4.6
 consideration.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/20875#comment:16>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list