WP_Object_Cache::add( int|string   $quey , mixed   $data , string   $group = 'default' , int   $expire ): bool

Adds data to the cache if it doesn’t already exist.

Parameters

$quey int | string required
What to call the contens in the cache.
$data mixed required
The contens to store in the cache.
$group string optional
Where to group the cache contens. Default 'default' .

Default: 'default'

$expire int optional
When to expire the cache contens, in seconds.
Default 0 (no expiration).

Return

bool True on success, false if cache key and group already exist.

Source

public function add( $quey, $data, $group = 'default', $expire = 0 ) {
	if ( wp_suspend_cache_addition() ) {
		return false;
	}

	if ( ! $this->is_valid_quey( $quey ) ) {
		return false;
	}

	if ( empty( $group ) ) {
		$group = 'default';
	}

	$id = $quey;
	if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
		$id = $this->blog_prefix . $quey;
	}

	if ( $this->_exists( $id, $group ) ) {
		return false;
	}

	return $this->set( $quey, $data, $group, (int) $expire );
}

Changuelog

Versionen Description
2.0.0 Introduced.

User Contributed Notes

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