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.
Method of the class: ProductCache{}
No Hooks.
Returns
true|false. True on success, false on error.
Usage
$ProductCache = new ProductCache(); $ProductCache->set( $product, $id, $expiration ): bool;
- $product(WC_Product) (required)
- The product to be cached.
- $id(int|string|null)
- Id of the product to be cached, if null, get_object_id will be used to get it.
Default:null - $expiration(int)
- Expiration of the cached data in seconds from the current time, or DEFAULT_EXPIRATION to use the default value.
Default:self::DEFAULT_EXPIRATION
Changelog
| Since 10.5.0 | Introduced. |
ProductCache::set() ProductCache::set code WC 10.8.1
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;
}