wp_cache_delete()
Deletes the cache by the specified key and group.
This function can be overridden by plugins. If you are using an object caching plugin, this function may work a little differently because its operation is defined separately. And this description shows how the basic WordPress function works.
Uses: WP_Object_Cache()
No Hooks.
Returns
true|false
. Boolean: true if the cache was successfully deleted and false on failure.
Usage
wp_cache_delete( $key, $group );
- $key(number/string) (required)
- The cache key to delete.
- $group(string)
- The name of the group in which to search for the specified key.
Default: ''
Examples
#1 Delete the previously set cache
This is a code snippet from the function clean_post_cache(). Here we remove cache of post 23, which was set into the 'posts'
and 'post_meta'
groups:
$post_id = 23; wp_cache_delete( $post_id, 'posts' ); wp_cache_delete( $post_id, 'post_meta' );
Notes
- See: WP_Object_Cache::delete()
- Global. WP_Object_Cache. $wp_object_cache Object cache global instance.
Changelog
Since 2.0.0 | Introduced. |
wp_cache_delete() wp cache delete code WP 6.8.1
function wp_cache_delete( $key, $group = '' ) { global $wp_object_cache; return $wp_object_cache->delete( $key, $group ); }