WordPress at a glance

wp_cache_add() WP 1.0

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

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. True on success, false if cache key and group already exist.

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)

Notes

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

Changelog

Since 2.0.0 Introduced.

Code of wp_cache_add() WP 5.5.1

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

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

From tag: cache (caching)

No comments
    Log In . Register