Skip to content

Commit

Permalink
[BUGS-6248] wp_cache_flush_runtime should only clear local cache (#413)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonny Harris <[email protected]>
  • Loading branch information
pwtyler and spacedmonkey committed May 11, 2023
1 parent 6b1145d commit 7be9fc3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ There's a known issue with WordPress `alloptions` cache design. Specifically, a
## Changelog ##

### Latest ###

* Bug fix: `wp_cache_flush_runtime` should only clear the local cache [[413](https://github.com/pantheon-systems/wp-redis/pull/413)]

### 1.4.0 (May 9, 2023) ###
* Add support for `flush_runtime` and `flush_group` functions [[#405](https://github.com/pantheon-systems/wp-redis/pull/405)]
Expand Down
4 changes: 3 additions & 1 deletion object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ function wp_cache_get_multiple( $keys, $group = '', $force = false ) {
* @return bool True on success, false on failure.
*/
function wp_cache_flush_runtime() {
return wp_cache_flush();
global $wp_object_cache;

return $wp_object_cache->flush( false );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ There's a known issue with WordPress `alloptions` cache design. Specifically, a
== Changelog ==

= Latest =

* Bug fix: `wp_cache_flush_runtime` should only clear the local cache [[413](https://github.com/pantheon-systems/wp-redis/pull/413)]

= 1.4.0 (May 9, 2023) =
* Add support for `flush_runtime` and `flush_group` functions [[#405](https://github.com/pantheon-systems/wp-redis/pull/405)]
Expand Down
10 changes: 9 additions & 1 deletion tests/phpunit/test-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,15 @@ public function test_wp_cache_flush_runtime() {
// Flush the cache
wp_cache_flush_runtime();

// Verify that the cache is now empty
// If we are using redis, verify redis cache was not flushed
if ($this->cache->is_redis_connected) {
foreach ( $data as $key => $value ) {
$this->assertEquals( $value, wp_cache_get( $key, 'test_wp_cache_flush_runtime' ) );
}
return;
}

// If we are not using redis, verify the cache is now empty
foreach ($data as $key => $value) {
$this->assertFalse( wp_cache_get( $key, 'test_wp_cache_flush_runtime' ) );
}
Expand Down

0 comments on commit 7be9fc3

Please sign in to comment.