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.

Method of the class: ObjectCache{}

No Hooks.


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(object|array) (required)
The new object that will replace the already cached one.
Id of the object to be cached, if null, get_object_id will be used to get it.
Default: null
Expiration of the cached data in seconds from the current time, or DEFAULT_EXPIRATION to use the default value.

ObjectCache::update_if_cached() code WC 9.0.1

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 );