Automattic\WooCommerce\Internal\Caches
ProductCache::set
Add a product to the cache, or update an already cached product.
Sets the clone mode to CACHE before storing to ensure meta IDs are preserved when WordPress object cache clones the object.
Метод класса: ProductCache{}
Хуков нет.
Возвращает
bool. True on success, false on error.
Использование
$ProductCache = new ProductCache(); $ProductCache->set( $product, $id, $expiration ): bool;
- $product(WC_Product) (обязательный)
- The product to be cached.
- $id(int|строка|null)
- Id of the product 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
Список изменений
| С версии 10.5.0 | Введена. |
Код ProductCache::set() ProductCache::set WC 11.2.2
public function set( $product, $id = null, int $expiration = self::DEFAULT_EXPIRATION ): bool {
if ( null !== $id ) {
$id = (int) $id;
}
$original_mode = $product->get_clone_mode();
$product->set_clone_mode( \WC_Data::CLONE_MODE_CACHE );
$result = parent::set( $product, $id, $expiration );
$product->set_clone_mode( $original_mode );
return $result;
}