WordPress at a glance

wp_cache_add() WP 1.0

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

Is the basis for: wp_load_alloptions()
Works based on: WP_Object_Cache::add()
✈ 1 time = 0.000168s = fast | 50000 times = 1.83s = fast | PHP 7.1.11, WP 4.9.8

No Hooks.


true/false. False if cache key and group already exist, true on success.


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)


  • See: WP_Object_Cache::add()
  • Global. WP_Object_Cache. $wp_object_cache Object cache global instance.


Since 2.0.0 Introduced.

Code of wp cache add: wp-includes/cache.php WP 5.2.4

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

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

Related Functions

From tag: cache (caching)

No comments
    Hello, !     Log In . Register