Skip to content

Commit

Permalink
Merge pull request #333 from pantheon-systems/fix-global-group-ignore…
Browse files Browse the repository at this point in the history
…-logic

Fix logic associated with `WP_REDIS_IGNORE_GLOBAL_GROUPS`
  • Loading branch information
danielbachhuber authored Oct 21, 2021
2 parents cfed7ac + 7b45878 commit ede1390
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
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.8
**Stable tag:** 1.1.3
**Stable tag:** 1.1.4
**License:** GPLv2 or later
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html

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

## Changelog ##

### 1.1.4 (October 21, 2021) ###
* Fixes some faulty logic in `WP_REDIS_IGNORE_GLOBAL_GROUPS` check [[#333](https://github.com/pantheon-systems/wp-redis/pull/333)].

### 1.1.3 (October 21, 2021) ###
* Supports a `WP_REDIS_IGNORE_GLOBAL_GROUPS` constant to prevent groups from being added to global caching group [[#331](https://github.com/pantheon-systems/wp-redis/pull/331)].

Expand Down
6 changes: 3 additions & 3 deletions object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,11 @@ public function add( $key, $data, $group = 'default', $expire = WP_REDIS_DEFAULT
public function add_global_groups( $groups ) {
$groups = (array) $groups;

// Filter global groups
// Allow force ignoring of global groups.
if ( is_array( WP_REDIS_IGNORE_GLOBAL_GROUPS ) ) {
$groups = array_diff_key( $groups, WP_REDIS_IGNORE_GLOBAL_GROUPS );
$groups = array_diff( $groups, WP_REDIS_IGNORE_GLOBAL_GROUPS );
}

$groups = array_fill_keys( $groups, true );
$this->global_groups = array_merge( $this->global_groups, $groups );
}
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.8
Stable tag: 1.1.3
Stable tag: 1.1.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

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

== Changelog ==

= 1.1.4 (October 21, 2021) =
* Fixes some faulty logic in `WP_REDIS_IGNORE_GLOBAL_GROUPS` check [[#333](https://github.com/pantheon-systems/wp-redis/pull/333)].

= 1.1.3 (October 21, 2021) =
* Supports a `WP_REDIS_IGNORE_GLOBAL_GROUPS` constant to prevent groups from being added to global caching group [[#331](https://github.com/pantheon-systems/wp-redis/pull/331)].

Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
define( 'WP_REDIS_USE_CACHE_GROUPS', true );
}

define( 'WP_REDIS_IGNORE_GLOBAL_GROUPS', array( 'wp-redis-ignored-group' ) );

// Easiest way to get this to where WordPress will load it
copy( dirname( dirname( dirname( __FILE__ ) ) ) . '/object-cache.php', $_core_dir . '/wp-content/object-cache.php' );

Expand Down
7 changes: 7 additions & 0 deletions tests/phpunit/test-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,13 @@ public function test_wp_cache_replace() {
$this->assertFalse( wp_cache_get( $fake_key ) );
}

public function test_ignore_global_groups() {
$this->cache->add_global_groups( array( 'wp-redis-respected-group' ) );
$this->assertTrue( isset( $this->cache->global_groups['wp-redis-respected-group'] ) );
$this->cache->add_global_groups( array( 'wp-redis-ignored-group' ) );
$this->assertFalse( isset( $this->cache->global_groups['wp-redis-ignored-group'] ) );
}

public function test_wp_redis_get_info() {
if ( ! class_exists( 'Redis' ) ) {
$this->markTestSkipped( 'PHPRedis extension not available.' );
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.3
* Version: 1.1.4
* Author: Pantheon, Josh Koenig, Matthew Boynes, Daniel Bachhuber, Alley Interactive
* Author URI: https://pantheon.io/
*/
Expand Down

0 comments on commit ede1390

Please sign in to comment.