From 5c9ff83290219bd7298cfd87099b3e17bd9e59f2 Mon Sep 17 00:00:00 2001 From: bc-toyin <95302437+bc-toyin@users.noreply.github.com> Date: Thu, 16 Nov 2023 16:44:42 -0600 Subject: [PATCH] cache product meta cache product meta --- src/BigCommerce/Post_Types/Product/Product.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/BigCommerce/Post_Types/Product/Product.php b/src/BigCommerce/Post_Types/Product/Product.php index 95944372..d83b40c5 100644 --- a/src/BigCommerce/Post_Types/Product/Product.php +++ b/src/BigCommerce/Post_Types/Product/Product.php @@ -1178,7 +1178,17 @@ private static function by_product_meta( $meta_key, $meta_value, \WP_Term $chann $args = array_merge( $args, $query_args ); - $posts = get_posts( $args ); + $cache_key = sprintf('product_meta_%s_%s', $meta_key, $meta_value); + + if ( $channel ) { + $cache_key .= '_' . $channel->term_id; + } + + $posts = wp_cache_get($cache_key); + if (!$posts) { + $posts = get_posts( $args ); + wp_cache_set($cache_key, $posts, '', 3600); + } if ( empty( $posts ) ) { throw new Product_Not_Found_Exception( sprintf( __( 'No product found matching %s %s', 'bigcommerce' ), strtoupper( $meta_key ), $meta_value ) );