wp_cache_set() WordPress Function

The wp_cache_set() function is used to add a value to the WordPress object cache. The object cache is a way to store data in memory for faster access. This function adds a value to the cache with a given key and expires time.

wp_cache_set( int|string $key, mixed $data, string $group = '', int $expire ) #

Saves the data to the cache.


Description

Differs from wp_cache_add() and wp_cache_replace() in that it will always write data.

Top ↑

See also


Top ↑

Parameters

$key

(int|string)(Required)The cache key to use for retrieval later.

$data

(mixed)(Required)The contents to store in the cache.

$group

(string)(Optional) Where to group the cache contents. Enables the same key to be used across groups.

Default value: ''

$expire

(int)(Optional) When to expire the cache contents, in seconds. Default 0 (no expiration).


Top ↑

Return

(bool) True on success, false on failure.


Top ↑

Source

File: 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 );
}


Top ↑

Changelog

Changelog
VersionDescription
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.