wp_cache_add
Adds data to the cache, if the cache key doesn't already exist.
Description
Parameters (4)
- 0. $key (int|string)
- The cache key to use for retrieval later.
- 1. $data (mixed)
- The data to add to the cache.
- 2. $group — Optional. (string) =>
''
- The group to add the cache to. Enables the same key to be used across groups. Default empty.
- 3. $expire — Optional. (int)
- When the cache data should expire, in seconds. Default 0 (no expiration).
Usage
if ( !function_exists( 'wp_cache_add' ) ) { require_once ABSPATH . WPINC . '/cache.php'; } // The cache key to use for retrieval later. $key = null; // The data to add to the cache. $data = null; // Optional. The group to add the cache to. Enables the same key // to be used across groups. Default empty. $group = ''; // Optional. When the cache data should expire, in seconds. // Default 0 (no expiration). $expire = -1; // NOTICE! Understand what this does before running. $result = wp_cache_add($key, $data, $group, $expire);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/cache.php
- function wp_cache_add( $key, $data, $group = '', $expire = 0 ) {
- global $wp_object_cache;
- return $wp_object_cache->add( $key, $data, $group, (int) $expire );
- }