mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Cache API: Add wp_cache_flush_group function.
Add a new plugable function called `wp_cache_flush_group`, that will allow developers to clear whole cache groups with a single call. Developers can detect if their current implementation of an object cache supports flushing by group, by calling `wp_cache_supports_group_flush` which returns true if it is supported. If the developers of the object cache drop-in has not implemented `wp_cache_flush_group` and `wp_cache_supports_group_flush`, these functions are polyfilled and `wp_cache_supports_group_flush` defaults to false. Props Spacedmonkey, filosofo, ryan, sc0ttkclark, SergeyBiryukov, scribu, Ste_95, dd32, dhilditch, dougal, lucasbustamante, dg12345, tillkruess, peterwilsoncc, flixos90, pbearne. Fixes #4476. git-svn-id: https://develop.svn.wordpress.org/trunk@53763 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -745,6 +745,17 @@ function wp_cache_init() {
|
||||
$wp_object_cache = new WP_Object_Cache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the object cache implementation supports flushing individual cache groups.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*
|
||||
* @return bool True if group flushing is supported, false otherwise.
|
||||
*/
|
||||
function wp_cache_supports_group_flush() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a group or set of groups to the list of non-persistent groups.
|
||||
*
|
||||
|
||||
@@ -415,4 +415,36 @@ class Tests_Cache extends WP_UnitTestCase {
|
||||
|
||||
$this->assertSame( $expected, $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 4476
|
||||
* @ticket 9773
|
||||
*
|
||||
* test wp_cache_flush_group
|
||||
*
|
||||
* @covers ::wp_cache_flush_group
|
||||
*/
|
||||
public function test_wp_cache_flush_group() {
|
||||
$key = 'my-key';
|
||||
$val = 'my-val';
|
||||
|
||||
wp_cache_set( $key, $val, 'group-test' );
|
||||
wp_cache_set( $key, $val, 'group-kept' );
|
||||
|
||||
$this->assertSame( $val, wp_cache_get( $key, 'group-test' ), 'test_wp_cache_flush_group: group-test should contain my-val' );
|
||||
|
||||
if ( wp_using_ext_object_cache() ) {
|
||||
$this->setExpectedIncorrectUsage( 'wp_cache_flush_group' );
|
||||
}
|
||||
|
||||
$results = wp_cache_flush_group( 'group-test' );
|
||||
|
||||
if ( wp_using_ext_object_cache() ) {
|
||||
$this->assertFalse( $results );
|
||||
} else {
|
||||
$this->assertTrue( $results );
|
||||
$this->assertFalse( wp_cache_get( $key, 'group-test' ), 'test_wp_cache_flush_group: group-test should return false' );
|
||||
$this->assertSame( $val, wp_cache_get( $key, 'group-kept' ), 'test_wp_cache_flush_group: group-kept should still contain my-val' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,6 +268,7 @@ class Tests_Pluggable extends WP_UnitTestCase {
|
||||
|
||||
// wp-includes/cache.php:
|
||||
'wp_cache_init' => array(),
|
||||
'wp_cache_supports_group_flush' => array(),
|
||||
'wp_cache_add' => array(
|
||||
'key',
|
||||
'data',
|
||||
@@ -327,6 +328,7 @@ class Tests_Pluggable extends WP_UnitTestCase {
|
||||
),
|
||||
'wp_cache_flush' => array(),
|
||||
'wp_cache_flush_runtime' => array(),
|
||||
'wp_cache_flush_group' => array( 'group' ),
|
||||
'wp_cache_close' => array(),
|
||||
'wp_cache_add_global_groups' => array( 'groups' ),
|
||||
'wp_cache_add_non_persistent_groups' => array( 'groups' ),
|
||||
|
||||
Reference in New Issue
Block a user