WP_Object_Cache::replace( int|string $key, mixed $data, string $group = 'default', int $expire )

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


Description Description

See also See also


Top ↑

Parameters Parameters

$key

(int|string) (Required) What to call the contents in the cache.

$data

(mixed) (Required) The contents to store in the cache.

$group

(string) (Optional) Where to group the cache contents.

Default value: 'default'

$expire

(int) (Optional) When to expire the cache contents. Default 0 (no expiration).


Top ↑

Return Return

(bool) False if not exists, true if contents were replaced.


Top ↑

Source Source

File: wp-includes/cache.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 );
	}

Top ↑

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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