wp_cache_get_salted( string $cache_key, string $group, string|string[] $salt ): mixed|false

In this article

Retrieves cached data if valid and unchanged.

Parameters

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

Return

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

Source

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'];
}

Changelog

VersionDescription
6.9.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.