Add support to prime refund cache in wc_order class.

Fetching refunds call is an expensive query, so priming the cache where possible could be beneficial for better performance.
This commit is contained in:
vedanshujain 2020-06-24 18:58:16 +05:30
parent b753189f64
commit 213397ffef
1 changed files with 10 additions and 0 deletions

View File

@ -1792,6 +1792,16 @@ class WC_Order extends WC_Abstract_Order {
|--------------------------------------------------------------------------
*/
/**
* Prime refunds cache, can be used before get_refunds to skip DB query.
*
* @param array $refunds array of WC_Order_Refund objects.
*/
public function prime_refunds_cache( $refunds ) {
$cache_key = WC_Cache_Helper::get_cache_prefix( 'orders' ) . 'refunds' . $this->get_id();
wp_cache_set( $cache_key, $refunds, $this->cache_group );
}
/**
* Get order refunds.
*