Skip to content

Commit 309c48a

Browse files
committedNov 28, 2019
Deprecated old cache function and replaced it with a new one.
1 parent b3115bc commit 309c48a

17 files changed

+43
-32
lines changed
 

‎includes/admin/settings/class-wc-settings-tax.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function save() {
128128
}
129129

130130
// Invalidate caches.
131-
WC_Cache_Helper::incr_cache_prefix( 'taxes' );
131+
WC_Cache_Helper::invalidate_cache_group( 'taxes' );
132132
WC_Cache_Helper::get_transient_version( 'shipping', true );
133133
// phpcs:enable WordPress.Security.NonceVerification.NoNonceVerification
134134
}

‎includes/class-wc-ajax.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2603,7 +2603,7 @@ public static function tax_rates_save_changes() {
26032603
}
26042604
}
26052605

2606-
WC_Cache_Helper::incr_cache_prefix( 'taxes' );
2606+
WC_Cache_Helper::invalidate_cache_group( 'taxes' );
26072607
WC_Cache_Helper::get_transient_version( 'shipping', true );
26082608

26092609
wp_send_json_success(

‎includes/class-wc-cache-helper.php

+11
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,17 @@ public static function get_cache_prefix( $group ) {
107107
* @param string $group Group of cache to clear.
108108
*/
109109
public static function incr_cache_prefix( $group ) {
110+
wc_deprecated_function( 'WC_Cache_Helper::incr_cache_prefix', '3.9.0', 'WC_Cache_Helper::invalidate_cache_group' );
111+
self::invalidate_cache_group( $group );
112+
}
113+
114+
/**
115+
* Invalidate cache group.
116+
*
117+
* @param string $group Group of cache to clear.
118+
* @since 3.9.0
119+
*/
120+
public static function invalidate_cache_group( $group ) {
110121
wp_cache_set( 'wc_' . $group . '_cache_prefix', microtime(), $group );
111122
}
112123

‎includes/class-wc-post-data.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ public static function delete_order_downloadable_permissions( $postid ) {
462462
* @param string $meta_value Meta value.
463463
*/
464464
public static function flush_object_meta_cache( $meta_id, $object_id, $meta_key, $meta_value ) {
465-
WC_Cache_Helper::incr_cache_prefix( 'object_' . $object_id );
465+
WC_Cache_Helper::invalidate_cache_group( 'object_' . $object_id );
466466
}
467467

468468
/**

‎includes/class-wc-session-handler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public function cleanup_sessions() {
302302
$wpdb->query( $wpdb->prepare( "DELETE FROM $this->_table WHERE session_expiry < %d", time() ) ); // @codingStandardsIgnoreLine.
303303

304304
if ( class_exists( 'WC_Cache_Helper' ) ) {
305-
WC_Cache_Helper::incr_cache_prefix( WC_SESSION_CACHE_GROUP );
305+
WC_Cache_Helper::invalidate_cache_group( WC_SESSION_CACHE_GROUP );
306306
}
307307
}
308308

‎includes/class-wc-tax.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ public static function delete_tax_class_by( $field, $item ) {
907907
}
908908

909909
wp_cache_delete( 'tax-rate-classes', 'taxes' );
910-
WC_Cache_Helper::incr_cache_prefix( 'taxes' );
910+
WC_Cache_Helper::invalidate_cache_group( 'taxes' );
911911

912912
return (bool) $delete;
913913
}
@@ -1025,7 +1025,7 @@ public static function _insert_tax_rate( $tax_rate ) {
10251025

10261026
$tax_rate_id = $wpdb->insert_id;
10271027

1028-
WC_Cache_Helper::incr_cache_prefix( 'taxes' );
1028+
WC_Cache_Helper::invalidate_cache_group( 'taxes' );
10291029

10301030
do_action( 'woocommerce_tax_rate_added', $tax_rate_id, $tax_rate );
10311031

@@ -1082,7 +1082,7 @@ public static function _update_tax_rate( $tax_rate_id, $tax_rate ) {
10821082
)
10831083
);
10841084

1085-
WC_Cache_Helper::incr_cache_prefix( 'taxes' );
1085+
WC_Cache_Helper::invalidate_cache_group( 'taxes' );
10861086

10871087
do_action( 'woocommerce_tax_rate_updated', $tax_rate_id, $tax_rate );
10881088
}
@@ -1101,7 +1101,7 @@ public static function _delete_tax_rate( $tax_rate_id ) {
11011101
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations WHERE tax_rate_id = %d;", $tax_rate_id ) );
11021102
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %d;", $tax_rate_id ) );
11031103

1104-
WC_Cache_Helper::incr_cache_prefix( 'taxes' );
1104+
WC_Cache_Helper::invalidate_cache_group( 'taxes' );
11051105

11061106
do_action( 'woocommerce_tax_rate_deleted', $tax_rate_id );
11071107
}
@@ -1176,7 +1176,7 @@ private static function update_tax_rate_locations( $tax_rate_id, $values, $type
11761176
$wpdb->query( "INSERT INTO {$wpdb->prefix}woocommerce_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES $sql;" ); // @codingStandardsIgnoreLine.
11771177
}
11781178

1179-
WC_Cache_Helper::incr_cache_prefix( 'taxes' );
1179+
WC_Cache_Helper::invalidate_cache_group( 'taxes' );
11801180
}
11811181

11821182
/**

‎includes/data-stores/class-wc-product-data-store-cpt.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -842,10 +842,10 @@ protected function clear_caches( &$product ) {
842842
wc_delete_product_transients( $product->get_id() );
843843
if ( $product->get_parent_id( 'edit' ) ) {
844844
wc_delete_product_transients( $product->get_parent_id( 'edit' ) );
845-
WC_Cache_Helper::incr_cache_prefix( 'product_' . $product->get_parent_id( 'edit' ) );
845+
WC_Cache_Helper::invalidate_cache_group( 'product_' . $product->get_parent_id( 'edit' ) );
846846
}
847847
WC_Cache_Helper::invalidate_attribute_count( array_keys( $product->get_attributes() ) );
848-
WC_Cache_Helper::incr_cache_prefix( 'product_' . $product->get_id() );
848+
WC_Cache_Helper::invalidate_cache_group( 'product_' . $product->get_id() );
849849
}
850850

851851
/*

‎includes/data-stores/class-wc-shipping-zone-data-store.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function create( &$zone ) {
3535
$zone->save_meta_data();
3636
$this->save_locations( $zone );
3737
$zone->apply_changes();
38-
WC_Cache_Helper::incr_cache_prefix( 'shipping_zones' );
38+
WC_Cache_Helper::invalidate_cache_group( 'shipping_zones' );
3939
WC_Cache_Helper::get_transient_version( 'shipping', true );
4040
}
4141

@@ -60,7 +60,7 @@ public function update( &$zone ) {
6060
$zone->save_meta_data();
6161
$this->save_locations( $zone );
6262
$zone->apply_changes();
63-
WC_Cache_Helper::incr_cache_prefix( 'shipping_zones' );
63+
WC_Cache_Helper::invalidate_cache_group( 'shipping_zones' );
6464
WC_Cache_Helper::get_transient_version( 'shipping', true );
6565
}
6666

@@ -132,7 +132,7 @@ public function delete( &$zone, $args = array() ) {
132132

133133
$zone->set_id( null );
134134

135-
WC_Cache_Helper::incr_cache_prefix( 'shipping_zones' );
135+
WC_Cache_Helper::invalidate_cache_group( 'shipping_zones' );
136136
WC_Cache_Helper::get_transient_version( 'shipping', true );
137137

138138
do_action( 'woocommerce_delete_shipping_zone', $zone_id );

‎includes/data-stores/class-wc-webhook-data-store.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function create( &$webhook ) {
6060
$webhook->apply_changes();
6161

6262
$this->delete_transients( $webhook->get_status( 'edit' ) );
63-
WC_Cache_Helper::incr_cache_prefix( 'webhooks' );
63+
WC_Cache_Helper::invalidate_cache_group( 'webhooks' );
6464
do_action( 'woocommerce_new_webhook', $webhook_id, $webhook );
6565
}
6666

@@ -157,7 +157,7 @@ public function update( &$webhook ) {
157157
$this->delete_transients( 'all' );
158158
}
159159
wp_cache_delete( $webhook->get_id(), 'webhooks' );
160-
WC_Cache_Helper::incr_cache_prefix( 'webhooks' );
160+
WC_Cache_Helper::invalidate_cache_group( 'webhooks' );
161161

162162
if ( 'active' === $webhook->get_status() && ( $trigger || $webhook->get_pending_delivery() ) ) {
163163
$webhook->deliver_ping();
@@ -184,7 +184,7 @@ public function delete( &$webhook ) {
184184
); // WPCS: cache ok, DB call ok.
185185

186186
$this->delete_transients( 'all' );
187-
WC_Cache_Helper::incr_cache_prefix( 'webhooks' );
187+
WC_Cache_Helper::invalidate_cache_group( 'webhooks' );
188188
do_action( 'woocommerce_webhook_deleted', $webhook->get_id(), $webhook );
189189
}
190190

‎includes/legacy/api/v2/class-wc-api-products.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ public function create_product_attribute( $data ) {
20232023

20242024
// Clear transients
20252025
delete_transient( 'wc_attribute_taxonomies' );
2026-
WC_Cache_Helper::incr_cache_prefix( 'woocommerce-attributes' );
2026+
WC_Cache_Helper::invalidate_cache_group( 'woocommerce-attributes' );
20272027

20282028
$this->server->send_status( 201 );
20292029

@@ -2109,7 +2109,7 @@ public function edit_product_attribute( $id, $data ) {
21092109

21102110
// Clear transients
21112111
delete_transient( 'wc_attribute_taxonomies' );
2112-
WC_Cache_Helper::incr_cache_prefix( 'woocommerce-attributes' );
2112+
WC_Cache_Helper::invalidate_cache_group( 'woocommerce-attributes' );
21132113

21142114
return $this->get_product_attribute( $id );
21152115
} catch ( WC_API_Exception $e ) {
@@ -2171,7 +2171,7 @@ public function delete_product_attribute( $id ) {
21712171

21722172
// Clear transients
21732173
delete_transient( 'wc_attribute_taxonomies' );
2174-
WC_Cache_Helper::incr_cache_prefix( 'woocommerce-attributes' );
2174+
WC_Cache_Helper::invalidate_cache_group( 'woocommerce-attributes' );
21752175

21762176
return array( 'message' => sprintf( __( 'Deleted %s', 'woocommerce' ), 'product_attribute' ) );
21772177
} catch ( WC_API_Exception $e ) {

‎includes/legacy/api/v3/class-wc-api-products.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2577,7 +2577,7 @@ public function create_product_attribute( $data ) {
25772577
// Clear transients.
25782578
wp_schedule_single_event( time(), 'woocommerce_flush_rewrite_rules' );
25792579
delete_transient( 'wc_attribute_taxonomies' );
2580-
WC_Cache_Helper::incr_cache_prefix( 'woocommerce-attributes' );
2580+
WC_Cache_Helper::invalidate_cache_group( 'woocommerce-attributes' );
25812581

25822582
$this->server->send_status( 201 );
25832583

@@ -2664,7 +2664,7 @@ public function edit_product_attribute( $id, $data ) {
26642664
// Clear transients.
26652665
wp_schedule_single_event( time(), 'woocommerce_flush_rewrite_rules' );
26662666
delete_transient( 'wc_attribute_taxonomies' );
2667-
WC_Cache_Helper::incr_cache_prefix( 'woocommerce-attributes' );
2667+
WC_Cache_Helper::invalidate_cache_group( 'woocommerce-attributes' );
26682668

26692669
return $this->get_product_attribute( $id );
26702670
} catch ( WC_API_Exception $e ) {
@@ -2727,7 +2727,7 @@ public function delete_product_attribute( $id ) {
27272727
// Clear transients.
27282728
wp_schedule_single_event( time(), 'woocommerce_flush_rewrite_rules' );
27292729
delete_transient( 'wc_attribute_taxonomies' );
2730-
WC_Cache_Helper::incr_cache_prefix( 'woocommerce-attributes' );
2730+
WC_Cache_Helper::invalidate_cache_group( 'woocommerce-attributes' );
27312731

27322732
return array( 'message' => sprintf( __( 'Deleted %s', 'woocommerce' ), 'product_attribute' ) );
27332733
} catch ( WC_API_Exception $e ) {

‎includes/wc-attribute-functions.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ function wc_create_attribute( $args ) {
611611
// Clear cache and flush rewrite rules.
612612
wp_schedule_single_event( time(), 'woocommerce_flush_rewrite_rules' );
613613
delete_transient( 'wc_attribute_taxonomies' );
614-
WC_Cache_Helper::incr_cache_prefix( 'woocommerce-attributes' );
614+
WC_Cache_Helper::invalidate_cache_group( 'woocommerce-attributes' );
615615

616616
return $id;
617617
}
@@ -701,7 +701,7 @@ function wc_delete_attribute( $id ) {
701701
do_action( 'woocommerce_attribute_deleted', $id, $name, $taxonomy );
702702
wp_schedule_single_event( time(), 'woocommerce_flush_rewrite_rules' );
703703
delete_transient( 'wc_attribute_taxonomies' );
704-
WC_Cache_Helper::incr_cache_prefix( 'woocommerce-attributes' );
704+
WC_Cache_Helper::invalidate_cache_group( 'woocommerce-attributes' );
705705

706706
return true;
707707
}

‎includes/wc-order-functions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ function wc_delete_shop_order_transients( $order = 0 ) {
464464
WC_Cache_Helper::get_transient_version( 'orders', true );
465465

466466
// Do the same for regular cache.
467-
WC_Cache_Helper::incr_cache_prefix( 'orders' );
467+
WC_Cache_Helper::invalidate_cache_group( 'orders' );
468468

469469
do_action( 'woocommerce_delete_shop_order_transients', $order_id );
470470
}

‎includes/wc-order-item-functions.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function wc_delete_order_item( $item_id ) {
104104
function wc_update_order_item_meta( $item_id, $meta_key, $meta_value, $prev_value = '' ) {
105105
$data_store = WC_Data_Store::load( 'order-item' );
106106
if ( $data_store->update_metadata( $item_id, $meta_key, $meta_value, $prev_value ) ) {
107-
WC_Cache_Helper::incr_cache_prefix( 'object_' . $item_id ); // Invalidate cache.
107+
WC_Cache_Helper::invalidate_cache_group( 'object_' . $item_id ); // Invalidate cache.
108108
return true;
109109
}
110110
return false;
@@ -126,7 +126,7 @@ function wc_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique = fal
126126
$meta_id = $data_store->add_metadata( $item_id, $meta_key, $meta_value, $unique );
127127

128128
if ( $meta_id ) {
129-
WC_Cache_Helper::incr_cache_prefix( 'object_' . $item_id ); // Invalidate cache.
129+
WC_Cache_Helper::invalidate_cache_group( 'object_' . $item_id ); // Invalidate cache.
130130
return $meta_id;
131131
}
132132
return 0;
@@ -146,7 +146,7 @@ function wc_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique = fal
146146
function wc_delete_order_item_meta( $item_id, $meta_key, $meta_value = '', $delete_all = false ) {
147147
$data_store = WC_Data_Store::load( 'order-item' );
148148
if ( $data_store->delete_metadata( $item_id, $meta_key, $meta_value, $delete_all ) ) {
149-
WC_Cache_Helper::incr_cache_prefix( 'object_' . $item_id ); // Invalidate cache.
149+
WC_Cache_Helper::invalidate_cache_group( 'object_' . $item_id ); // Invalidate cache.
150150
return true;
151151
}
152152
return false;

‎includes/wc-update-functions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ function wc_update_220_attributes() {
674674
}
675675

676676
delete_transient( 'wc_attribute_taxonomies' );
677-
WC_Cache_Helper::incr_cache_prefix( 'woocommerce-attributes' );
677+
WC_Cache_Helper::invalidate_cache_group( 'woocommerce-attributes' );
678678
}
679679

680680
/**

‎tests/framework/helpers/class-wc-helper-product.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public static function create_attribute( $raw_name = 'size', $terms = array( 'sm
224224

225225
// Make sure caches are clean.
226226
delete_transient( 'wc_attribute_taxonomies' );
227-
WC_Cache_Helper::incr_cache_prefix( 'woocommerce-attributes' );
227+
WC_Cache_Helper::invalidate_cache_group( 'woocommerce-attributes' );
228228

229229
// These are exported as labels, so convert the label to a name if possible first.
230230
$attribute_labels = wp_list_pluck( wc_get_attribute_taxonomies(), 'attribute_label', 'attribute_name' );

‎tests/framework/helpers/class-wc-helper-shipping-zones.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ public static function remove_mock_zones() {
5151
$wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_shipping_zone_methods;" );
5252
$wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_shipping_zone_locations;" );
5353
$wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_shipping_zones;" );
54-
WC_Cache_Helper::incr_cache_prefix( 'shipping_zones' );
54+
WC_Cache_Helper::invalidate_cache_group( 'shipping_zones' );
5555
}
5656
}

0 commit comments

Comments
 (0)
Please sign in to comment.