-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add $found
parameter to wp_cache_get_multiple()
#4258
base: trunk
Are you sure you want to change the base?
Add $found
parameter to wp_cache_get_multiple()
#4258
Conversation
@peterwilsoncc Do memcache and redis support this? |
Memcache does, I've updated the implementation in the test suite to do so. @tillkruess do you know if redis supports it? |
Sorry, wrong username, @tillkruss do you know if redis supports passing found by reference when getting multiple objects? |
Yes, it could be added to the plugins. But Litespeed, W3TC and others are pretty stale and won't support this for a long time. |
Does this serve a purpose in core? How could this be used in the real world, isn't the false value already giving us this information? |
Mainly, it makes the getter API for single and multiple cache objects consistent.
Often but not always, the real world implication is when the cached object is Core caches false values in some places but not many. In some circumstances, it's quite common that a false needs to be cached. function pw_slow_function( $result ) {
sleep( 2 );
return $result;
}
wp_cache_set( 'foo', pw_slow_function( false ) );
wp_cache_set( 'bar', pw_slow_function( true ) );
$values = wp_cache_get_multiple( [ 'foo', bar' ] );
foreach ( $values as $key => $values ) {
if ( ! $value ) {
$value = pw_slow_function( /* as above */ );
wp_cache_set( $key, $value );
}
} |
The consistency makes sense. Just for public record, storing falsy values is always risky and often leads to silent errors. |
I don't think Memcached and Redis can reliably support this, because if a user stores Checking for existence first doubles to lookup. It's like running Typically WordPress expects non existing cache keys to return I'm not sure this PR makes sense, the root issue is what the user code does. |
I'll investigate further to make sure it's working as expected. For wordpress-develop/tests/phpunit/includes/object-cache.php Lines 1468 to 1471 in 464ad20
For get multi, maybe it's possible to use Does Redis have an equivalent, I notice the docs reference the return value |
I do think that redis could support this functionality. See this method. It might tricky, but I see how it could be done. Consider that I am really struggling to get cache plugins even support wp_cache_get_multiple. https://wordpress.org/support/topic/implement-function-wp_cache_get_multiple/ I have more this ^ |
That's just using Redis's But it's just ambitious to store
😞 |
Combination of patches on trac ticket WP#57743