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|stringrequired
What to call the contents in the cache.
$datamixedrequired
The contents to store in the cache.
$groupstringoptional
Where to group the cache contents. Default 'default'.

Default:'default'

$expireintoptional
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

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 );
}

Changelog

VersionDescription
2.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.