mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-01 19:24:34 +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:
@@ -22,6 +22,19 @@ function wp_cache_init() {
|
||||
$GLOBALS['wp_object_cache'] = new WP_Object_Cache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the object cache implementation supports flushing individual cache groups.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*
|
||||
* @see WP_Object_Cache::flush_group()
|
||||
*
|
||||
* @return bool True if group flushing is supported, false otherwise.
|
||||
*/
|
||||
function wp_cache_supports_group_flush() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds data to the cache, if the cache key doesn't already exist.
|
||||
*
|
||||
@@ -281,6 +294,25 @@ function wp_cache_flush_runtime() {
|
||||
return wp_cache_flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all cache items in a group, if the object cache implementation supports it.
|
||||
* Before calling this method, always check for group flushing support using the
|
||||
* `wp_cache_supports_group_flush()` method.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*
|
||||
* @see WP_Object_Cache::flush_group()
|
||||
* @global WP_Object_Cache $wp_object_cache Object cache global instance.
|
||||
*
|
||||
* @param string $group Name of group to remove from cache.
|
||||
* @return bool True if group was flushed, false otherwise.
|
||||
*/
|
||||
function wp_cache_flush_group( $group ) {
|
||||
global $wp_object_cache;
|
||||
|
||||
return $wp_object_cache->flush_group( $group );
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the cache.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user