diff --git a/README.md b/README.md index e808dd5..4330298 100644 --- a/README.md +++ b/README.md @@ -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)] diff --git a/object-cache.php b/object-cache.php index 5211a69..c607bd1 100644 --- a/object-cache.php +++ b/object-cache.php @@ -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 ); } /** diff --git a/readme.txt b/readme.txt index f48b2b4..ccf2c00 100644 --- a/readme.txt +++ b/readme.txt @@ -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)] diff --git a/tests/phpunit/test-cache.php b/tests/phpunit/test-cache.php index fac2e28..e731ca6 100644 --- a/tests/phpunit/test-cache.php +++ b/tests/phpunit/test-cache.php @@ -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' ) ); }