wp_cache_set_salted( string $cache_key, mixed $data, string $group, string|string[] $salt, int $expire = 0 ): bool
- Since
- 6.9.0
- Source
wp-includes/cache-compat.php:244
Compatibility
- WordPress
- since 6.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 3 of the 5 tracked releases, added in 6.9.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$cache_keystring- The cache key under which to store the data.
$datamixed- The data to be cached.
$groupstring- The cache group to which the data belongs.
$saltstring|string[]- The timestamp (or multiple timestamps if an array) indicating when the cache group(s) were last updated.
$expireintoptional- When to expire the cache contents, in seconds.
Default 0 (no expiration).Default:0
Return value
bool- True on success, false on failure.
Performance profile
How much work a call to wp_cache_set_salted() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Constant
- Instructions
- 18–19
- Plugin surface
- None
- Called by
- 14
Only touches the object cache, via wp_cache_set_salted().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 20.
Nothing here hands control to plugin code.
14 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- cacheobject cache
wp_cache_set_salted()this function does it
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_cache_set_salted() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 18–19 | data() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 20 | 18–19 | 1 | |
| 8.5 | 20 | 18–19 | 1 | |
| 8.4 | 20 | 18–19 | 1 | 4 fewer instructions than PHP 8.3 |
| 8.3 | 24 | 18–23 | 1 | |
| 8.2 | 24 | 18–23 | 1 | |
| 8.1 | 24 | 18–23 | 1 | |
| 7.4 | 24 | 18–23 | 1 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 1
- wp_cache_set()Saves the data to the cache.
Used by · 14
- WP_Comment_Query::get_comments()Get a list of comments matching the query vars.
- WP_Network_Query::get_networks()Gets a list of networks matching the query vars.
- WP_Query::get_posts()Retrieves an array of posts based on query variables.
- WP_Site_Query::get_sites()Retrieves a list of sites matching the query vars.
- WP_Term_Query::get_terms()Retrieves the query results.
- WP_User_Query::query()Executes the query, with the current variables.
- _find_post_by_old_date()Find the post ID for redirecting an old date.
- _find_post_by_old_slug()Find the post ID for redirecting an old slug.
- count_many_users_posts()Gets the number of posts written by a list of users.
- count_user_posts()Gets the number of posts a user has written.
- get_adjacent_post()Retrieves the adjacent post.
- get_objects_in_term()Retrieves object IDs of valid taxonomy and term.
Show all 14
- get_page_by_path()Retrieves a page given its path.
- wp_get_archives()Displays archive links based on type and format.
Source code
function wp_cache_set_salted( $cache_key, $data, $group, $salt, $expire = 0 ) { $salt = is_array( $salt ) ? implode( ':', $salt ) : $salt; return wp_cache_set( $cache_key, array( 'data' => $data, 'salt' => $salt, ), $group, $expire ); }Changelog
Introduced in 6.9.0. Unchanged from 6.9.7 through 7.1.0.
Signature, return type and hooks compared across 3 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/cache-compat.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.