Automattic\WooCommerce\Caching

ObjectCache::update_if_cached()publicWC 1.0

Update an object in the cache, but only if an object is already cached with the same id.

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

Хуков нет.

Возвращает

true|false. True on success, false on error or if no object wiith the supplied id was cached.

Использование

$ObjectCache = new ObjectCache();
$ObjectCache->update_if_cached( $object, $id, $expiration ): bool;
$object(объект|массив) (обязательный)
The new object that will replace the already cached one.
$id(int|строка|null)
Id of the object to be cached, if null, get_object_id will be used to get it.
По умолчанию: null
$expiration(int)
Expiration of the cached data in seconds from the current time, or DEFAULT_EXPIRATION to use the default value.
По умолчанию: self::DEFAULT_EXPIRATION

Код ObjectCache::update_if_cached() WC 8.7.0

public function update_if_cached( $object, $id = null, int $expiration = self::DEFAULT_EXPIRATION ): bool {
	$id = $this->get_id_from_object_if_null( $object, $id );

	if ( ! $this->is_cached( $id ) ) {
		return false;
	}

	return $this->set( $object, $id, $expiration );
}