Skip to content

Commit c937a1a

Browse files
Cache API: Make the placement of wp_cache_flush_group() more consistent.
Includes: * Placing `WP_Object_Cache::flush_group()` next to `::flush()`. * Placing `wp_cache_supports_group_flush()` next to `wp_cache_flush_group()`. * Placing the `wp_cache_flush_group()` unit test next to the `::flush()` method test. * Removing test name from assertion messages, as it is already mentioned directly above in case of failure. * Adjusting function descriptions per the documentation standards. Follow-up to [52706], [53763]. See #55647, WordPress#4476. git-svn-id: https://develop.svn.wordpress.org/trunk@53767 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f0ddd2e commit c937a1a

6 files changed

Lines changed: 76 additions & 76 deletions

File tree

src/wp-includes/cache-compat.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ function wp_cache_flush_runtime() {
145145
if ( ! function_exists( 'wp_cache_flush_group' ) ) :
146146
/**
147147
* Removes all cache items in a group, if the object cache implementation supports it.
148-
* Before calling this method, always check for group flushing support using the
149-
* `wp_cache_supports_group_flush()` method.
148+
*
149+
* Before calling this function, always check for group flushing support using the
150+
* `wp_cache_supports_group_flush()` function.
150151
*
151152
* @since 6.1.0
152153
*
@@ -175,7 +176,7 @@ function wp_cache_flush_group( $group ) {
175176

176177
if ( ! function_exists( 'wp_cache_supports_group_flush' ) ) :
177178
/**
178-
* Whether the object cache implementation supports flushing individual cache groups.
179+
* Determines whether the object cache implementation supports flushing individual cache groups.
179180
*
180181
* @since 6.1.0
181182
*

src/wp-includes/cache.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,6 @@ function wp_cache_init() {
2222
$GLOBALS['wp_object_cache'] = new WP_Object_Cache();
2323
}
2424

25-
/**
26-
* Whether the object cache implementation supports flushing individual cache groups.
27-
*
28-
* @since 6.1.0
29-
*
30-
* @see WP_Object_Cache::flush_group()
31-
*
32-
* @return bool True if group flushing is supported, false otherwise.
33-
*/
34-
function wp_cache_supports_group_flush() {
35-
return true;
36-
}
37-
3825
/**
3926
* Adds data to the cache, if the cache key doesn't already exist.
4027
*
@@ -296,8 +283,9 @@ function wp_cache_flush_runtime() {
296283

297284
/**
298285
* Removes all cache items in a group, if the object cache implementation supports it.
299-
* Before calling this method, always check for group flushing support using the
300-
* `wp_cache_supports_group_flush()` method.
286+
*
287+
* Before calling this function, always check for group flushing support using the
288+
* `wp_cache_supports_group_flush()` function.
301289
*
302290
* @since 6.1.0
303291
*
@@ -313,6 +301,19 @@ function wp_cache_flush_group( $group ) {
313301
return $wp_object_cache->flush_group( $group );
314302
}
315303

304+
/**
305+
* Determines whether the object cache implementation supports flushing individual cache groups.
306+
*
307+
* @since 6.1.0
308+
*
309+
* @see WP_Object_Cache::flush_group()
310+
*
311+
* @return bool True if group flushing is supported, false otherwise.
312+
*/
313+
function wp_cache_supports_group_flush() {
314+
return true;
315+
}
316+
316317
/**
317318
* Closes the cache.
318319
*

src/wp-includes/class-wp-object-cache.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -290,20 +290,6 @@ public function set_multiple( array $data, $group = '', $expire = 0 ) {
290290
return $values;
291291
}
292292

293-
/**
294-
* Removes all cache items in a group.
295-
*
296-
* @since 6.1.0
297-
*
298-
* @param string $group Name of group to remove from cache.
299-
* @return true Always returns true.
300-
*/
301-
public function flush_group( $group ) {
302-
unset( $this->cache[ $group ] );
303-
304-
return true;
305-
}
306-
307293
/**
308294
* Retrieves the cache contents, if it exists.
309295
*
@@ -509,6 +495,20 @@ public function flush() {
509495
return true;
510496
}
511497

498+
/**
499+
* Removes all cache items in a group.
500+
*
501+
* @since 6.1.0
502+
*
503+
* @param string $group Name of group to remove from cache.
504+
* @return true Always returns true.
505+
*/
506+
public function flush_group( $group ) {
507+
unset( $this->cache[ $group ] );
508+
509+
return true;
510+
}
511+
512512
/**
513513
* Sets the list of global cache groups.
514514
*

tests/phpunit/includes/object-cache.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,17 @@ function wp_cache_flush( $delay = 0 ) {
284284
return $wp_object_cache->flush( $delay );
285285
}
286286

287+
/**
288+
* Whether the object cache implementation supports flushing individual cache groups.
289+
*
290+
* @since 6.1.0
291+
*
292+
* @return bool True if group flushing is supported, false otherwise.
293+
*/
294+
function wp_cache_supports_group_flush() {
295+
return false;
296+
}
297+
287298
/**
288299
* Retrieves object from cache.
289300
*
@@ -745,17 +756,6 @@ function wp_cache_init() {
745756
$wp_object_cache = new WP_Object_Cache();
746757
}
747758

748-
/**
749-
* Whether the object cache implementation supports flushing individual cache groups.
750-
*
751-
* @since 6.1.0
752-
*
753-
* @return bool True if group flushing is supported, false otherwise.
754-
*/
755-
function wp_cache_supports_group_flush() {
756-
return false;
757-
}
758-
759759
/**
760760
* Adds a group or set of groups to the list of non-persistent groups.
761761
*

tests/phpunit/tests/cache.php

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,36 @@ public function test_flush() {
129129
$this->assertFalse( $this->cache->get( $key ) );
130130
}
131131

132+
/**
133+
* @ticket 4476
134+
* @ticket 9773
135+
*
136+
* @covers ::wp_cache_flush_group
137+
*/
138+
public function test_wp_cache_flush_group() {
139+
$key = 'my-key';
140+
$val = 'my-val';
141+
142+
wp_cache_set( $key, $val, 'group-test' );
143+
wp_cache_set( $key, $val, 'group-kept' );
144+
145+
$this->assertSame( $val, wp_cache_get( $key, 'group-test' ), 'group-test should contain my-val' );
146+
147+
if ( wp_using_ext_object_cache() ) {
148+
$this->setExpectedIncorrectUsage( 'wp_cache_flush_group' );
149+
}
150+
151+
$results = wp_cache_flush_group( 'group-test' );
152+
153+
if ( wp_using_ext_object_cache() ) {
154+
$this->assertFalse( $results );
155+
} else {
156+
$this->assertTrue( $results );
157+
$this->assertFalse( wp_cache_get( $key, 'group-test' ), 'group-test should return false' );
158+
$this->assertSame( $val, wp_cache_get( $key, 'group-kept' ), 'group-kept should still contain my-val' );
159+
}
160+
}
161+
132162
// Make sure objects are cloned going to and from the cache.
133163
public function test_object_refs() {
134164
$key = __FUNCTION__ . '_1';
@@ -415,36 +445,4 @@ public function test_wp_cache_delete_multiple() {
415445

416446
$this->assertSame( $expected, $found );
417447
}
418-
419-
/**
420-
* @ticket 4476
421-
* @ticket 9773
422-
*
423-
* test wp_cache_flush_group
424-
*
425-
* @covers ::wp_cache_flush_group
426-
*/
427-
public function test_wp_cache_flush_group() {
428-
$key = 'my-key';
429-
$val = 'my-val';
430-
431-
wp_cache_set( $key, $val, 'group-test' );
432-
wp_cache_set( $key, $val, 'group-kept' );
433-
434-
$this->assertSame( $val, wp_cache_get( $key, 'group-test' ), 'test_wp_cache_flush_group: group-test should contain my-val' );
435-
436-
if ( wp_using_ext_object_cache() ) {
437-
$this->setExpectedIncorrectUsage( 'wp_cache_flush_group' );
438-
}
439-
440-
$results = wp_cache_flush_group( 'group-test' );
441-
442-
if ( wp_using_ext_object_cache() ) {
443-
$this->assertFalse( $results );
444-
} else {
445-
$this->assertTrue( $results );
446-
$this->assertFalse( wp_cache_get( $key, 'group-test' ), 'test_wp_cache_flush_group: group-test should return false' );
447-
$this->assertSame( $val, wp_cache_get( $key, 'group-kept' ), 'test_wp_cache_flush_group: group-kept should still contain my-val' );
448-
}
449-
}
450448
}

tests/phpunit/tests/pluggable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ public function get_pluggable_function_signatures() {
268268

269269
// wp-includes/cache.php:
270270
'wp_cache_init' => array(),
271-
'wp_cache_supports_group_flush' => array(),
272271
'wp_cache_add' => array(
273272
'key',
274273
'data',
@@ -329,6 +328,7 @@ public function get_pluggable_function_signatures() {
329328
'wp_cache_flush' => array(),
330329
'wp_cache_flush_runtime' => array(),
331330
'wp_cache_flush_group' => array( 'group' ),
331+
'wp_cache_supports_group_flush' => array(),
332332
'wp_cache_close' => array(),
333333
'wp_cache_add_global_groups' => array( 'groups' ),
334334
'wp_cache_add_non_persistent_groups' => array( 'groups' ),

0 commit comments

Comments
 (0)