WordPress at a glance

wp_cache_add() WP 1.0

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

Notes:

  • See: WP_Object_Cache::add()
  • Global. WP_Object_Cache. $wp_object_cache Object cache global instance.
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.

Return

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

Usage

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.
$group(string)
The group to add the cache to. Enables the same key to be used across groups.
Default: ''
$expire(int)
When the cache data should expire, in seconds.
Default: 0 (no expiration)

Code of wp_cache_add: wp-includes/cache.php VER 4.9.8

<?php
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