On this page
wp_cache_add( int|string $key, mixed $data, string $group = '', int $expire ): bool
Adds data to the cache, if the cache key doesn’t already exist.
Description
See also
Parameters
$keyint|string Required-
The cache key to use for retrieval later.
$datamixed Required-
The data to add to the cache.
$groupstring Optional-
The group to add the cache to. Enables the same key to be used across groups.
Default:
'' $expireint Optional-
When the cache data should expire, in seconds.
Default 0 (no expiration).
Return
bool True on success, false if cache key and group already exist.
Source
File: wp-includes/cache.php. View all references
function wp_cache_add( $key, $data, $group = '', $expire = 0 ) {
global $wp_object_cache;
return $wp_object_cache->add( $key, $data, $group, (int) $expire );
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Object_Cache::add() wp-includes/class-wp-object-cache.php | Adds data to the cache if it doesn’t already exist. |
Used By
| Used By | Description |
|---|---|
| WP_Term_Query::get_terms() wp-includes/class-wp-term-query.php | Retrieves the query results. |
| WP_Network_Query::get_networks() wp-includes/class-wp-network-query.php | Gets a list of networks matching the query vars. |
| ms_load_current_site_and_network() wp-includes/ms-load.php | Identifies the network and site of a requested domain and path and populates the corresponding network and site global objects as part of the multisite bootstrap process. |
| WP_Site_Query::get_sites() wp-includes/class-wp-site-query.php | Retrieves a list of sites matching the query vars. |
| WP_Site::get_instance() wp-includes/class-wp-site.php | Retrieves a site from the database by its ID. |
| WP_Network::get_instance() wp-includes/class-wp-network.php | Retrieves a network from the database by its ID. |
| WP_Comment::get_instance() wp-includes/class-wp-comment.php | Retrieves a WP_Comment instance. |
| WP_Term::get_instance() wp-includes/class-wp-term.php | Retrieve WP_Term instance. |
| WP_Comment_Query::get_comments() wp-includes/class-wp-comment-query.php | Get a list of comments matching the query vars. |
| get_terms_to_edit() wp-admin/includes/taxonomy.php | Gets comma-separated list of terms available to edit for the given post ID. |
| get_inline_data() wp-admin/includes/template.php | Adds hidden fields with the data for use in the inline editor for posts and pages. |
| get_the_terms() wp-includes/category-template.php | Retrieves the terms of the taxonomy that are attached to the post. |
| WP_Theme::cache_add() wp-includes/class-wp-theme.php | Adds theme data to cache. |
| WP_Query::get_posts() wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables. |
| wp_load_alloptions() wp-includes/option.php | Loads and caches all autoloaded options, if available or all options. |
| get_option() wp-includes/option.php | Retrieves an option value based on an option name. |
| update_user_caches() wp-includes/user.php | Updates all user caches. |
| WP_Post::get_instance() wp-includes/class-wp-post.php | Retrieve WP_Post instance. |
| wp_mime_type_icon() wp-includes/post.php | Retrieves the icon for a MIME type or attachment. |
| get_all_page_ids() wp-includes/post.php | Gets a list of page IDs. |
| get_bookmark() wp-includes/bookmark.php | Retrieves bookmark data. |
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_add