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|stringrequired- The cache key to use for retrieval later.
$datamixedrequired- The contents to store in the cache.
$groupstringoptional- Where to group the cache contents. Enables the same key to be used across groups.
Default:
'' $expireintoptional- When to expire the cache contents, in seconds.
Default 0 (no expiration).
Return
bool True on success, false on failure.Source
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 | Description |
|---|---|
WP_Object_Cache::set()wp-includes/class-wp-object-cache.php | Sets the data contents into the cache. |
| Used by | Description |
|---|---|
wp_prime_network_option_caches()wp-includes/option.php | Primes specific network options into the cache with a single database query. |
WP_Textdomain_Registry::get_language_files_from_path()wp-includes/class-wp-textdomain-registry.php | Retrieves translation files from the specified path. |
wp_prime_option_caches()wp-includes/option.php | Primes specific options into the cache with a single database query. |
wp_set_option_autoload_values()wp-includes/option.php | Sets the autoload values for multiple options in the database. |
wp_get_theme_data_template_parts()wp-includes/global-styles-and-settings.php | Returns the metadata for the template parts defined by the theme. |
wp_cache_set_last_changed()wp-includes/functions.php | Sets last changed date for the specified cache group to now. |
wp_get_global_styles_custom_css()wp-includes/deprecated.php | Gets the global styles custom CSS from theme.json. |
wp_get_global_styles_svg_filters()wp-includes/deprecated.php | Returns a string containing the SVGs to be referenced as filters (duotone). |
wp_get_global_settings()wp-includes/global-styles-and-settings.php | Gets the settings resulting of merging core, theme, and user data. |
wp_get_global_stylesheet()wp-includes/global-styles-and-settings.php | Returns the stylesheet resulting of merging core, theme, and user data. |
_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 | Counts the 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_Term_Query::get_terms()wp-includes/class-wp-term-query.php | Retrieves the query results. |
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. |
delete_network_option()wp-includes/option.php | Removes a network option by name. |
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. |
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 an option by name. Prevents removal of protected WordPress options. |
get_option()wp-includes/option.php | Retrieves an option value based on an option name. |
count_user_posts()wp-includes/user.php | Gets the number of posts a user has written. |
_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. |
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). |
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. |
get_blog_details()wp-includes/ms-blogs.php | Retrieves the details for a blog from the blogs table and blog options. |
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. |
Requests made to third-party endpoints should be cached, regardless of being synchronous or asynchronous. Not doing so will result in your site’s load time depending on an unreliable API response!