Summery Summery

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

Syntax Syntax

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

Parameters Parameters


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


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


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

Default value: 'default'


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

Return Return

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

Source Source

File: wp-includes/class-wp-object-cache.php

	public function add( $key, $data, $group = 'default', $expire = 0 ) {
		if ( wp_suspend_cache_addition() ) {
			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 Changelog

Version Description
2.0.0 Introduced.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.