Skip to content

Commit

Permalink
Add support for flush_runtime and flush_group
Browse files Browse the repository at this point in the history
  • Loading branch information
John Spellman committed May 1, 2023
1 parent 1c3e155 commit f2feb21
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions object-cache.php
Expand Up @@ -155,6 +155,35 @@ function wp_cache_get_multiple( $keys, $group = '', $force = false ) {
return $wp_object_cache->get_multiple( $keys, $group, $force );
}

/**
* Removes all cache items from the in-memory runtime cache.
*
* @see WP_Object_Cache::flush()
*
* @return bool True on success, false on failure.
*/
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 function, always check for group flushing support using the
* `wp_cache_supports( 'flush_group' )` function.
*
* @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 );
}

/**
* Increment numeric cache item's value
*
Expand Down Expand Up @@ -302,13 +331,13 @@ function wp_cache_reset() {
function wp_cache_supports( $feature ) {
switch ( $feature ) {
case 'get_multiple':
case 'flush_runtime':
case 'flush_group':
return true;

case 'add_multiple':
case 'set_multiple':
case 'delete_multiple':
case 'flush_runtime':
case 'flush_group':
default:
return false;
}
Expand Down Expand Up @@ -637,6 +666,18 @@ public function flush( $redis = true ) {
return true;
}

/**
* Removes all cache items in a group.
*
* @param string $group Name of group to remove from cache.
* @return true Always returns true.
*/
public function flush_group( $group ) {
unset( $this->cache[ $group ] );

return true;
}

/**
* Retrieves the cache contents, if it exists
*
Expand Down

0 comments on commit f2feb21

Please sign in to comment.