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

[BUGS-6248] wp_cache_flush_runtime should only clear local cache #413

Merged
merged 5 commits into from
May 11, 2023
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
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