wp_cache_add( int|string $key, mixed $data, string $group = '', int $expire ): bool

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


Top ↑

See also

Top ↑


$key int|string Required
The cache key to use for retrieval later.
$data mixed Required
The data to add to the cache.
$group string Optional
The group to add the cache to. Enables the same key to be used across groups.

Default: ''

$expire int Optional
When the cache data should expire, in seconds.
Default 0 (no expiration).

Top ↑


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

Top ↑


File: wp-includes/cache.php. View all references

function wp_cache_add( $key, $data, $group = '', $expire = 0 ) {
	global $wp_object_cache;

	return $wp_object_cache->add( $key, $data, $group, (int) $expire );

Top ↑


Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes

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