Skip to content
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

Return cache data in correct order when using wp_cache_get_multiple() #292

Merged
merged 7 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
**Tags:** cache, plugin, redis
**Requires at least:** 3.0.1
**Tested up to:** 5.5
**Stable tag:** 1.1.0
**Stable tag:** 1.1.1
**License:** GPLv2 or later
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -107,6 +107,9 @@ There's a known issue with WordPress `alloptions` cache design. Specifically, a

## Changelog ##

### 1.1.1 (August 17, 2020) ###
* Returns cache data in correct order when using `wp_cache_get_multiple()` and internal cache is already primed [[#292](https://github.com/pantheon-systems/wp-redis/pull/292)].

### 1.1.0 (July 13, 2020) ###
* Implements `wp_cache_get_multiple()` for WordPress 5.5 [[#287](https://github.com/pantheon-systems/wp-redis/pull/287)].
* Bails early when connecting to Redis throws an Exception to avoid fatal error [[285](https://github.com/pantheon-systems/wp-redis/pull/285)].
Expand Down
3 changes: 2 additions & 1 deletion object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,14 +694,15 @@ public function get_multiple( $keys, $group = 'default', $force = false ) {
}
}
}
$remaining_keys = array_diff( $keys, array_keys( $cache ) );
$remaining_keys = array_values( array_diff( $keys, array_keys( $cache ) ) );
// If all keys were satisfied by the internal cache, we're sorted.
if ( empty( $remaining_keys ) ) {
return $cache;
}
if ( $this->_should_use_redis_hashes( $group ) ) {
$redis_safe_group = $this->_key( '', $group );
$results = $this->_call_redis( 'hmGet', $redis_safe_group, $remaining_keys );
$results = is_array( $results ) ? array_values( $results ) : $results;
} else {
$ids = array();
foreach ( $remaining_keys as $key ) {
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: getpantheon, danielbachhuber, mboynes, Outlandish Josh
Tags: cache, plugin, redis
Requires at least: 3.0.1
Tested up to: 5.5
Stable tag: 1.1.0
Stable tag: 1.1.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -107,6 +107,9 @@ There's a known issue with WordPress `alloptions` cache design. Specifically, a

== Changelog ==

= 1.1.1 (August 17, 2020) =
* Returns cache data in correct order when using `wp_cache_get_multiple()` and internal cache is already primed [[#292](https://github.com/pantheon-systems/wp-redis/pull/292)].

= 1.1.0 (July 13, 2020) =
* Implements `wp_cache_get_multiple()` for WordPress 5.5 [[#287](https://github.com/pantheon-systems/wp-redis/pull/287)].
* Bails early when connecting to Redis throws an Exception to avoid fatal error [[285](https://github.com/pantheon-systems/wp-redis/pull/285)].
Expand Down
34 changes: 34 additions & 0 deletions tests/phpunit/test-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,40 @@ public function test_get_multiple() {
}
}

public function test_get_multiple_partial_cache_miss() {
if ( ! class_exists( 'Redis' ) ) {
$this->markTestSkipped( 'Requires an active persistent object cache connection' );
}
$this->cache->set( 'foo1', 'bar', 'group1' );
$this->cache->set( 'foo2', 'baz', 'group1' );
$this->cache->set( 'foo3', 'bap', 'group1' );
// Reset the internal cache.
$this->cache->cache = array();
// Prime the second item into the internal cache.
$this->cache->get( 'foo2', 'group1' );

$found = $this->cache->get_multiple( array( 'foo1', 'foo2', 'foo3', 'foo4' ), 'group1' );

$expected = array(
'foo1' => 'bar',
'foo2' => 'baz',
'foo3' => 'bap',
'foo4' => false,
);

$this->assertSame( $expected, $found );
$this->assertEquals( 4, $this->cache->cache_hits );
$this->assertEquals( 1, $this->cache->cache_misses );
$this->assertEquals(
array(
self::$get_key => 1,
self::$mget_key => 1,
self::$set_key => 3,
),
$this->cache->redis_calls
);
}

public function test_get_multiple_non_persistent() {
$this->cache->add_non_persistent_groups( array( 'group1' ) );
$this->cache->set( 'foo1', 'bar', 'group1' );
Expand Down
2 changes: 1 addition & 1 deletion wp-redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WP Redis
* Plugin URI: http://github.com/pantheon-systems/wp-redis/
* Description: WordPress Object Cache using Redis. Requires the PhpRedis extension (https://github.com/phpredis/phpredis).
* Version: 1.1.0
* Version: 1.1.1
* Author: Pantheon, Josh Koenig, Matthew Boynes, Daniel Bachhuber, Alley Interactive
* Author URI: https://pantheon.io/
*/
Expand Down