Saves the data to the cache.
Description
Differs from wp_cache_add() and wp_cache_replace() in that it will always write data.
See also
Parameters
$key
int|stringrequired- The cache key to use for retrieval later.
$data
mixedrequired- The contents to store in the cache.
$group
stringoptional- Where to group the cache contents. Enables the same key to be used across groups.
Default:
''
$expire
intoptional- When to expire the cache contents, in seconds.
Default 0 (no expiration).
Source
function wp_cache_set( $key, $data, $group = '', $expire = 0 ) {
global $wp_object_cache;
return $wp_object_cache->set( $key, $data, $group, (int) $expire );
}
Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |
Requests made to third-party endpoints should be cached, regardless of being synchronous or asynchronous. Not doing so will result in your site’s load time depending on an unreliable API response!