Skip to content

Commit 7be9fc3

Browse files
pwtylerspacedmonkey
andcommitted
[BUGS-6248] wp_cache_flush_runtime should only clear local cache (#413)
Co-authored-by: Jonny Harris <jon@spacedmonkey.co.uk>
1 parent 6b1145d commit 7be9fc3

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ There's a known issue with WordPress `alloptions` cache design. Specifically, a
105105
## Changelog ##
106106

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

110110
### 1.4.0 (May 9, 2023) ###
111111
* Add support for `flush_runtime` and `flush_group` functions [[#405](https://github.com/pantheon-systems/wp-redis/pull/405)]

object-cache.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ function wp_cache_get_multiple( $keys, $group = '', $force = false ) {
165165
* @return bool True on success, false on failure.
166166
*/
167167
function wp_cache_flush_runtime() {
168-
return wp_cache_flush();
168+
global $wp_object_cache;
169+
170+
return $wp_object_cache->flush( false );
169171
}
170172

171173
/**

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ There's a known issue with WordPress `alloptions` cache design. Specifically, a
103103
== Changelog ==
104104

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

108108
= 1.4.0 (May 9, 2023) =
109109
* Add support for `flush_runtime` and `flush_group` functions [[#405](https://github.com/pantheon-systems/wp-redis/pull/405)]

tests/phpunit/test-cache.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,15 @@ public function test_wp_cache_flush_runtime() {
410410
// Flush the cache
411411
wp_cache_flush_runtime();
412412

413-
// Verify that the cache is now empty
413+
// If we are using redis, verify redis cache was not flushed
414+
if ($this->cache->is_redis_connected) {
415+
foreach ( $data as $key => $value ) {
416+
$this->assertEquals( $value, wp_cache_get( $key, 'test_wp_cache_flush_runtime' ) );
417+
}
418+
return;
419+
}
420+
421+
// If we are not using redis, verify the cache is now empty
414422
foreach ($data as $key => $value) {
415423
$this->assertFalse( wp_cache_get( $key, 'test_wp_cache_flush_runtime' ) );
416424
}

0 commit comments

Comments
 (0)