wp_cache_get_salted()WP 6.9.0

Retrieves cached data if valid and unchanged.

No Hooks.

Returns

Mixed|false. The cached data if valid, or false if the cache does not exist or is outdated.

Usage

wp_cache_get_salted( $cache_key, $group, $salt );
$cache_key(string) (required)
The cache key used for storage and retrieval.
$group(string) (required)
The cache group used for organizing data.
$salt(string|string[]) (required)
The timestamp (or multiple timestamps if an array) indicating when the cache group(s) were last updated.

Changelog

Since 6.9.0 Introduced.

wp_cache_get_salted() code WP 6.9.1

function wp_cache_get_salted( $cache_key, $group, $salt ) {
	$salt  = is_array( $salt ) ? implode( ':', $salt ) : $salt;
	$cache = wp_cache_get( $cache_key, $group );

	if ( ! is_array( $cache ) ) {
		return false;
	}

	if ( ! isset( $cache['salt'] ) || ! isset( $cache['data'] ) || $salt !== $cache['salt'] ) {
		return false;
	}

	return $cache['data'];
}