WC_Helper_Updater::should_use_cached_update_data
Validates cached update data and checks if it matches the expected hash.
Ensures the cached data is properly structured, corresponds to the current payload, and was not expired by a refresh, to avoid fatal errors and stale cache returns.
Method of the class: WC_Helper_Updater{}
No Hooks.
Returns
bool. True if the data is valid and hash matches, false otherwise.
Usage
$result = WC_Helper_Updater::should_use_cached_update_data( $data, $hash );
- $data(mixed) (required)
- The data retrieved from the transient.
- $hash(string) (required)
- The expected hash to compare against.
Changelog
| Since 10.3.6 | Introduced. |
WC_Helper_Updater::should_use_cached_update_data() WC Helper Updater::should use cached update data code WC 11.3.0
private static function should_use_cached_update_data( $data, $hash ) {
if ( ! is_array( $data ) || ! empty( $data['expired'] ) || ! self::is_fresh_update_data( $data ) ) {
return false;
}
if ( ! isset( $data['hash'], $data['products'] ) ) {
return false;
}
if ( ! is_string( $data['hash'] ) || ! is_array( $data['products'] ) ) {
return false;
}
return hash_equals( $hash, $data['hash'] );
}