WordPress at a glance
function is not described

WP_Object_Cache::replace() public WP 2.0.0

Replaces the contents in the cache, if contents already exist.

{} It's a method of the class: WP_Object_Cache{}

No Hooks.

Return

true|false. False if not exists, true if contents were replaced.

Usage

$WP_Object_Cache = new WP_Object_Cache();
$WP_Object_Cache->replace( $key, $data, $group, $expire );
$key(int|string) (required)
What to call the contents in the cache.
$data(mixed) (required)
The contents to store in the cache.
$group(string)
Where to group the cache contents.
Default: 'default'
$expire(int)
When to expire the cache contents.
Default: 0 (no expiration)

Notes

  • See: WP_Object_Cache::set()

Changelog

Since 2.0.0 Introduced.

Code of WP_Object_Cache::replace() WP 5.7.2

<?php
public function replace( $key, $data, $group = 'default', $expire = 0 ) {
	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 );
}