On this page
WP_Object_Cache::replace( int|string $key, mixed $data, string $group = 'default', int $expire ): bool
Replaces the contents in the cache, if contents already exist.
Description
See also
Parameters
$keyint|string Required-
What to call the contents in the cache.
$datamixed Required-
The contents to store in the cache.
$groupstring Optional-
Where to group the cache contents. Default
'default'.Default:
'default' $expireint Optional-
When to expire the cache contents, in seconds.
Default 0 (no expiration).
Return
bool True if contents were replaced, false if original value does not exist.
Source
File: wp-includes/class-wp-object-cache.php. View all references
public function replace( $key, $data, $group = 'default', $expire = 0 ) {
if ( ! $this->is_valid_key( $key ) ) {
return false;
}
if ( empty( $group ) ) {
$group = 'default';
}
$id = $key;
if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
$id = $this->blog_prefix . $key;
}
if ( ! $this->_exists( $id, $group ) ) {
return false;
}
return $this->set( $key, $data, $group, (int) $expire );
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Object_Cache::is_valid_key() wp-includes/class-wp-object-cache.php | Serves as a utility function to determine whether a key is valid. |
| WP_Object_Cache::_exists() wp-includes/class-wp-object-cache.php | Serves as a utility function to determine whether a key exists in the cache. |
| 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_replace() wp-includes/cache.php | Replaces the contents of the cache with new data. |
Changelog
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_object_cache/replace