Add cache invalidation for wc_get_product_terms

Closes #17369
This commit is contained in:
Mike Jolley 2017-10-25 13:27:18 +01:00
parent f8552ebbad
commit a467d35acd
2 changed files with 5 additions and 3 deletions

View File

@ -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() );
}
/*

View File

@ -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;
}