wp_cache_set
Saves the data to the cache.
Description
Differs from wp_cache_add(…)
and wp_cache_replace(…)
in that it will always write data.
Parameters (4)
- 0. $key (int|string)
- The cache key to use for retrieval later.
- 1. $data (mixed)
- The contents to store in the cache.
- 2. $group — Optional. (string) =>
''
- Where to group the cache contents. Enables the same key to be used across groups. Default empty.
- 3. $expire — Optional. (int)
- When to expire the cache contents, in seconds. Default 0 (no expiration).
Usage
if ( !function_exists( 'wp_cache_set' ) ) { require_once ABSPATH . WPINC . '/cache.php'; } // The cache key to use for retrieval later. $key = null; // The contents to store in the cache. $data = null; // Optional. Where to group the cache contents. Enables the same key // to be used across groups. Default empty. $group = ''; // Optional. When to expire the cache contents, in seconds. // Default 0 (no expiration). $expire = -1; // NOTICE! Understand what this does before running. $result = wp_cache_set($key, $data, $group, $expire);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/cache.php
- function wp_cache_set( $key, $data, $group = '', $expire = 0 ) {
- global $wp_object_cache;
- return $wp_object_cache->set( $key, $data, $group, (int) $expire );
- }