On this page
wp_cache_set( int|string $key, mixed $data, string $group = '', int $expire ): bool
Saves the data to the cache.
Description
Differs from wp_cache_add() and wp_cache_replace() in that it will always write data.
See also
Parameters
$keyint|string Required-
The cache key to use for retrieval later.
$datamixed Required-
The contents to store in the cache.
$groupstring Optional-
Where to group the cache contents. Enables the same key to be used across groups.
Default:
'' $expireint Optional-
When to expire the cache contents, in seconds.
Default 0 (no expiration).
Return
bool True on success, false on failure.
Source
File: wp-includes/cache.php. View all references
function wp_cache_set( $key, $data, $group = '', $expire = 0 ) {
global $wp_object_cache;
return $wp_object_cache->set( $key, $data, $group, (int) $expire );
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Object_Cache::set() wp-includes/class-wp-object-cache.php | Sets the data contents into the cache. |
Used By
| Used By | Description |
|---|---|
| wp_cache_set_sites_last_changed() wp-includes/ms-site.php | Sets the last changed time for the ‘sites’ cache group. |
| wp_cache_set_terms_last_changed() wp-includes/taxonomy.php | Sets the last changed time for the ‘terms’ cache group. |
| wp_cache_set_comments_last_changed() wp-includes/comment.php | Sets the last changed time for the ‘comment’ cache group. |
| wp_cache_set_posts_last_changed() wp-includes/post.php | Sets the last changed time for the ‘posts’ cache group. |
| _find_post_by_old_slug() wp-includes/query.php | Find the post ID for redirecting an old slug. |
| _find_post_by_old_date() wp-includes/query.php | Find the post ID for redirecting an old date. |
| WP_Privacy_Requests_Table::get_request_counts() wp-admin/includes/class-wp-privacy-requests-table.php | Count number of requests for each status. |
| WP_Embed::find_oembed_post_id() wp-includes/class-wp-embed.php | Finds the oEmbed cache post ID for a given cache key. |
| WP_Customize_Manager::find_changeset_post_id() wp-includes/class-wp-customize-manager.php | Finds the changeset post ID for a given changeset UUID. |
| wp_cache_get_last_changed() wp-includes/functions.php | Gets last changed date for the specified cache group. |
| WP_Term_Query::get_terms() wp-includes/class-wp-term-query.php | Retrieves the query results. |
| clean_network_cache() wp-includes/ms-network.php | Removes a network from the object cache. |
| WP_Site::get_details() wp-includes/class-wp-site.php | Retrieves the details for this site. |
| update_network_option() wp-includes/option.php | Updates the value of a network option that was already added. |
| add_network_option() wp-includes/option.php | Adds a new network option. |
| get_network_option() wp-includes/option.php | Retrieves a network’s option value based on the option name. |
| WP_MS_Sites_List_Table::column_users() wp-admin/includes/class-wp-ms-sites-list-table.php | Handles the users column output. |
| get_plugins() wp-admin/includes/plugin.php | Checks the plugins directory and retrieve all plugin files with plugin data. |
| wp_get_archives() wp-includes/general-template.php | Displays archive links based on type and format. |
| get_calendar() wp-includes/general-template.php | Displays calendar with days that have posts as links. |
| WP_Query::get_posts() wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables. |
| is_blog_installed() wp-includes/functions.php | Determines whether WordPress is already installed. |
| is_object_in_term() wp-includes/taxonomy.php | Determines if the given object is associated with any of the given terms. |
| clean_term_cache() wp-includes/taxonomy.php | Removes all of the term IDs from the cache. |
| get_objects_in_term() wp-includes/taxonomy.php | Retrieves object IDs of valid taxonomy and term. |
| get_adjacent_post() wp-includes/link-template.php | Retrieves the adjacent post. |
| set_site_transient() wp-includes/option.php | Sets/updates the value of a site transient. |
| set_transient() wp-includes/option.php | Sets/updates the value of a transient. |
| update_option() wp-includes/option.php | Updates the value of an option that was already added. |
| add_option() wp-includes/option.php | Adds a new option. |
| delete_option() wp-includes/option.php | Removes option by name. Prevents removal of protected WordPress options. |
| get_option() wp-includes/option.php | Retrieves an option value based on an option name. |
| clean_post_cache() wp-includes/post.php | Will clean the post in the cache. |
| _get_last_post_time() wp-includes/post.php | Gets the timestamp of the last time any post was modified or published. |
| get_page_by_path() wp-includes/post.php | Retrieves a page given its path. |
| get_pages() wp-includes/post.php | Retrieves an array of pages (or hierarchical post type items). |
| wp_count_posts() wp-includes/post.php | Counts number of posts of a post type and if user has permissions to view. |
| wp_count_attachments() wp-includes/post.php | Counts number of attachments for the mime type(s). |
| wpmu_create_blog() wp-includes/ms-functions.php | Creates a site. |
| get_blog_id_from_url() wp-includes/ms-functions.php | Gets a blog’s numeric ID from its URL. |
| get_bookmarks() wp-includes/bookmark.php | Retrieves the list of bookmarks. |
| clean_blog_cache() wp-includes/ms-site.php | Clean the blog cache |
| get_blog_details() wp-includes/ms-blogs.php | Retrieve the details for a blog from the blogs table and blog options. |
| clean_comment_cache() wp-includes/comment.php | Removes a comment from the object cache. |
| wp_count_comments() wp-includes/comment.php | Retrieves the total comment counts for the whole site or a single post. |
| get_lastcommentmodified() wp-includes/comment.php | Retrieves the date the last comment was modified. |
Changelog
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_cache_set