Add caching to product factory
This commit is contained in:
parent
767a1e500e
commit
709d314ca7
|
@ -45,7 +45,15 @@ class WC_Product_Factory {
|
|||
}
|
||||
|
||||
try {
|
||||
return new $classname( $product_id );
|
||||
// Try to get from cache, otherwise create a new object,
|
||||
$product = wp_cache_get( WC_Cache_Helper::get_cache_prefix( 'product-' . $product_id ), 'products' );
|
||||
|
||||
if ( ! is_a( $product, 'WC_Product' ) ) {
|
||||
$product = new $classname( $product_id );
|
||||
wp_cache_set( WC_Cache_Helper::get_cache_prefix( 'product-' . $product_id ), $product, 'products' );
|
||||
}
|
||||
|
||||
return $product;
|
||||
} catch ( Exception $e ) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -615,6 +615,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
*/
|
||||
protected function clear_caches( &$product ) {
|
||||
wc_delete_product_transients( $product->get_id() );
|
||||
WC_Cache_Helper::incr_cache_prefix( 'product-' . $product->get_id() );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue