wp_cache_add()WP 2.0.0

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

1 time — 0.000168 sec (fast) | 50000 times — 1.83 sec (fast) | PHP 7.1.11, WP 4.9.8

No Hooks.


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


wp_cache_add( $key, $data, $group, $expire );
$key(int|string) (required)
The cache key to use for retrieval later.
$data(mixed) (required)
The data to add to the cache.
The group to add the cache to. Enables the same key to be used across groups.
Default: ''
When the cache data should expire, in seconds.
Default: 0 (no expiration)



Since 2.0.0 Introduced.

Code of wp_cache_add() WP 6.0

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

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