WordPress at a glance

wp_cache_set() WP 1.0

Saves the data to the cache.

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

Notes:

  • See: WP_Object_Cache::set()
  • Global. WP_Object_Cache. $wp_object_cache Object cache global instance.
Works based on: WP_Object_Cache::set()
✈ 1 time = 0.000174s = fast | 50000 times = 1.98s = fast PHP 7.1.11, WP 4.9.8

No Hooks.

Return

true/false. False on failure, true on success

Usage

wp_cache_set( $key, $data, $group, $expire );
$key(int/string) (required)
The cache key to use for retrieval later.
$data(mixed) (required)
The contents to store in the cache.
$group(string)
Where to group the cache contents. Enables the same key to be used across groups.
Default: ''
$expire(int)
When to expire the cache contents, in seconds.
Default: 0 (no expiration)

Code of wp_cache_set: wp-includes/cache.php VER 4.9.8

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

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

Related Functions

From tag: cache (caching)

No comments
    Hello, !     Log In . Register