WC_Cache_Helper::get_transient_version()public staticWC 1.0

Get transient version.

When using transients with unpredictable names, e.g. those containing an md5 hash in the name, we need a way to invalidate them all at once.

When using default WP transients we're able to do this with a DB query to delete transients manually.

With external cache however, this isn't possible. Instead, this function is used to append a unique string (based on time()) to each transient. When transients are invalidated, the transient version will increment and data will be regenerated.

Raised in issue https://github.com/woocommerce/woocommerce/issues/5777. Adapted from ideas in http://tollmanz.com/invalidation-schemes/.

Метод класса: WC_Cache_Helper{}

Хуков нет.


Строку. transient version based on time(), 10 digits.


$result = WC_Cache_Helper::get_transient_version( $group, $refresh );
$group(строка) (обязательный)
Name for the group of transients we need to invalidate.
true to force a new version.
По умолчанию: false

Код WC_Cache_Helper::get_transient_version() WC 8.9.3

public static function get_transient_version( $group, $refresh = false ) {
	$transient_name  = $group . '-transient-version';
	$transient_value = get_transient( $transient_name );

	if ( false === $transient_value || true === $refresh ) {
		$transient_value = (string) time();

		set_transient( $transient_name, $transient_value );

	return $transient_value;