Merge pull request #17372 from woocommerce/fix/17369
Add cache invalidation for wc_get_product_terms
This commit is contained in:
commit
a396a6c83e
|
@ -760,6 +760,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() );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -51,8 +51,9 @@ function wc_get_object_terms( $object_id, $taxonomy, $field = null, $index_key =
|
|||
* @return array
|
||||
*/
|
||||
function _wc_get_cached_product_terms( $product_id, $taxonomy, $args = array() ) {
|
||||
$cache_key = 'wc_' . $taxonomy . md5( json_encode( $args ) );
|
||||
$terms = wp_cache_get( $product_id, $cache_key );
|
||||
$cache_key = 'wc_' . $taxonomy . md5( json_encode( $args ) );
|
||||
$cache_group = WC_Cache_Helper::get_cache_prefix( 'product_' . $product_id ) . $product_id;
|
||||
$terms = wp_cache_get( $cache_key, $cache_group );
|
||||
|
||||
if ( false !== $terms ) {
|
||||
return $terms;
|
||||
|
@ -62,7 +63,7 @@ function _wc_get_cached_product_terms( $product_id, $taxonomy, $args = array() )
|
|||
$terms = wp_get_post_terms( $product_id, $taxonomy, $args );
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
wp_cache_add( $product_id, $terms, $cache_key );
|
||||
wp_cache_add( $cache_key, $terms, $cache_group );
|
||||
|
||||
return $terms;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue