[ Web Proxy ]
URL:
Viewing: https://developer.wordpress.org/reference/functions/wp_cache_delete/ [Back]  [Original]

wp_cache_delete() Function | Developer.WordPress.org Skip to content
WordPress.org

wp_cache_delete( int|string $key, string $group = '' ): bool

Removes the cache contents matching key and group.

Description

See also

Parameters

$keyint|stringrequired
What the contents in the cache are called.
$groupstringoptional
Where the cache contents are grouped.

Default:''

Return

bool True on successful removal, false on failure.

Source

function wp_cache_delete( $key, $group = '' ) {
	global $wp_object_cache;

	return $wp_object_cache->delete( $key, $group );
}
UsesDescription
WP_Object_Cache::delete()wp-includes/class-wp-object-cache.php

Removes the contents of the cache key in the group.

Used byDescription
WP_AI_Client_Cache::delete()wp-includes/ai-client/adapters/class-wp-ai-client-cache.php

Delete an item from the cache by its unique key.

WP_Textdomain_Registry::invalidate_mo_files_cache()wp-includes/class-wp-textdomain-registry.php

Invalidate the cache for .mo files.

wp_set_option_autoload_values()wp-includes/option.php

Sets the autoload values for multiple options in the database.

wp_clean_theme_json_cache()wp-includes/global-styles-and-settings.php

Cleans the caches under the theme_json group.

populate_network_meta()wp-admin/includes/schema.php

Creates WordPress network meta and sets the default values.

populate_site_meta()wp-admin/includes/schema.php

Creates WordPress site meta and sets the default values.

clean_taxonomy_cache()wp-includes/taxonomy.php

Cleans the caches for a taxonomy.

clean_site_details_cache()wp-includes/ms-blogs.php

Cleans the site details cache for a site.

delete_network_option()wp-includes/option.php

Removes a network option by name.

wp_clean_plugins_cache()wp-admin/includes/plugin.php

Clears the plugins cache used by get_plugins() and by default, the plugin updates cache.

update_core()wp-admin/includes/update-core.php

Upgrades the core of WordPress.

delete_get_calendar_cache()wp-includes/general-template.php

Purges the cached results of get_calendar.

delete_usermeta()wp-includes/deprecated.php

Remove user meta data.

update_usermeta()wp-includes/deprecated.php

Update metadata of user.

WP_Theme::cache_delete()wp-includes/class-wp-theme.php

Clears the cache for the theme.

wp_set_object_terms()wp-includes/taxonomy.php

Creates term and taxonomy relationships.

wp_remove_object_terms()wp-includes/taxonomy.php

Removes term(s) associated with a given object.

delete_site_transient()wp-includes/option.php

Deletes a site transient.

update_option()wp-includes/option.php

Updates the value of an option that was already added.

delete_option()wp-includes/option.php

Removes an option by name. Prevents removal of protected WordPress options.

delete_transient()wp-includes/option.php

Deletes a transient.

clean_user_cache()wp-includes/user.php

Cleans all user caches.

clean_post_cache()wp-includes/post.php

Will clean the post in the cache.

clean_attachment_cache()wp-includes/post.php

Will clean the attachment in the cache.

_transition_post_status()wp-includes/post.php

Hook for managing future post transitions to published.

_wp_upgrade_revisions_of_post()wp-includes/revision.php

Upgrades the revisions author, adds the current post as a revision and sets the revisions version to 1.

clean_bookmark_cache()wp-includes/bookmark.php

Deletes the bookmark cache.

add_user_to_blog()wp-includes/ms-functions.php

Adds a user to a blog, along with specifying the user’s role.

clean_blog_cache()wp-includes/ms-site.php

Clean the blog cache

get_blog_details()wp-includes/ms-blogs.php

Retrieves the details for a blog from the blogs table and blog options.

wp_update_comment_count_now()wp-includes/comment.php

Updates the comment count for the post.

update_metadata_by_mid()wp-includes/meta.php

Updates metadata by meta ID.

delete_metadata_by_mid()wp-includes/meta.php

Deletes metadata by meta ID.

add_metadata()wp-includes/meta.php

Adds metadata for the specified object.

update_metadata()wp-includes/meta.php

Updates metadata for the specified object. If no value already exists for the specified object ID and metadata key, the metadata will be added.

Show 30 moreShow less

Changelog

VersionDescription
2.0.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Let’s say before making an SQL request to retrieve all the data rows of a table in your database, you check for a cache and, if there isn’t one, set one.

    function wpdocs_all_rows_getter() {
    	global $wpdb;
    	$table_name = $wpdb->prefix . 'wpdocs_table';
    
    	$cache_key = 'wpdocs_cache_key';
    	$results   = wp_cache_get( $cache_key );
    
    	if ( ! $results ) {
    		$results = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %s', $table_name ) );
    		// Set the cache.
    		wp_cache_set( $cache_key, $results, 'wpdocs_cache_group', 3600 );
    	}
    
    	return $results;
    }

    If you later delete a single row from the table, you’ll also have to delete the cache you set earlier to ensure data consistency.

    function wpdocs_single_row_deleter( $id ) {
    	global $wpdb;
    	$table_name = $wpdb->prefix . 'my_custom_table';
    
    	$rows_deleted = $wpdb->delete( $table_name, array( 'id' => $id ) );
    
    	if ( 0 < $rows_deleted ) {
    		$result = true;
    		// Clear the cache.
    		wp_cache_delete( 'wpdocs_cache_key', 'wpdocs_cache_group' );
    	} else {
    		$result = false;
    	}
    
    	return $result;
    }
    Log in to add feedback

You must log in before being able to contribute a note or feedback.


Web Proxy Viewer  |  New URL  |  Original Page