diff --git a/README.md b/README.md index 10c91ecc..962bc448 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,27 @@ Errors if the object cache can't be flushed. +### wp cache flush-group + +Removes all cache items in a group, if the object cache implementation supports it. + +~~~ +wp cache flush-group +~~~ + +**OPTIONS** + + + Cache group key. + +**EXAMPLES** + + # Clear cache group. + $ wp cache flush-group my_group + Success: Cache group 'my_group' was flushed. + + + ### wp cache get Gets a value from the object cache. diff --git a/composer.json b/composer.json index 3fbceb9c..b5294858 100644 --- a/composer.json +++ b/composer.json @@ -37,6 +37,7 @@ "cache decr", "cache delete", "cache flush", + "cache flush-group", "cache get", "cache incr", "cache replace", diff --git a/features/cache.feature b/features/cache.feature index c6cb71f0..0626dfd5 100644 --- a/features/cache.feature +++ b/features/cache.feature @@ -133,6 +133,59 @@ Feature: Managed the WordPress object cache Error: Could not replace object 'bar' in group 'foo'. Does it not exist? """ + @require-wp-6.1 + Scenario: Some cache groups cannot be cleared. + Given a WP install + When I run `wp cache flush-group add_multiple` + Then STDOUT should be: + """ + Success: Cache group 'add_multiple' was flushed. + """ + + @require-wp-6.1 + Scenario: Some cache groups cannot be cleared. + Given a WP install + And a wp-content/mu-plugins/unclearable-test-cache.php file: + """php + + * : Cache group key. + * + * ## EXAMPLES + * + * # Clear cache group. + * $ wp cache flush-group my_group + * Success: Cache group 'my_group' was flushed. + * + * @subcommand flush-group + */ + public function flush_group( $args, $assoc_args ) { + list( $group ) = $args; + + if ( ! function_exists( 'wp_cache_supports' ) || ! wp_cache_supports( 'flush_group' ) ) { + WP_CLI::error( 'Group flushing is not supported.' ); + } + + if ( ! wp_cache_flush_group( $group ) ) { + WP_CLI::error( "Cache group '$group' was not flushed." ); + } + WP_CLI::success( "Cache group '$group' was flushed." ); + } + }