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0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / class-wc-cache-helper.php
woocommerce / includes Last commit date
abstracts 4 years ago admin 4 years ago blocks 5 years ago cli 4 years ago customizer 4 years ago data-stores 4 years ago emails 4 years ago export 4 years ago gateways 4 years ago import 4 years ago integrations 5 years ago interfaces 4 years ago legacy 4 years ago libraries 6 years ago log-handlers 5 years ago payment-tokens 5 years ago queue 4 years ago react-admin 4 years ago rest-api 4 years ago shipping 4 years ago shortcodes 5 years ago theme-support 4 years ago tracks 4 years ago traits 5 years ago walkers 5 years ago wccom-site 5 years ago widgets 4 years ago class-wc-ajax.php 4 years ago class-wc-api.php 4 years ago class-wc-auth.php 4 years ago class-wc-autoloader.php 5 years ago class-wc-background-emailer.php 5 years ago class-wc-background-updater.php 5 years ago class-wc-breadcrumb.php 5 years ago class-wc-cache-helper.php 4 years ago class-wc-cart-fees.php 5 years ago class-wc-cart-session.php 4 years ago class-wc-cart-totals.php 4 years ago class-wc-cart.php 4 years ago class-wc-checkout.php 4 years ago class-wc-cli.php 4 years ago class-wc-comments.php 4 years ago class-wc-countries.php 4 years ago class-wc-coupon.php 4 years ago class-wc-customer-download-log.php 5 years ago class-wc-customer-download.php 4 years ago class-wc-customer.php 4 years ago class-wc-data-exception.php 8 years ago class-wc-data-store.php 6 years ago class-wc-datetime.php 4 years ago class-wc-deprecated-action-hooks.php 8 years ago class-wc-deprecated-filter-hooks.php 4 years ago class-wc-discounts.php 4 years ago class-wc-download-handler.php 4 years ago class-wc-emails.php 5 years ago class-wc-embed.php 5 years ago class-wc-form-handler.php 4 years ago class-wc-frontend-scripts.php 4 years ago class-wc-geo-ip.php 4 years ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 4 years ago class-wc-https.php 4 years ago class-wc-install.php 4 years ago class-wc-integrations.php 5 years ago class-wc-log-levels.php 5 years ago class-wc-logger.php 4 years ago class-wc-meta-data.php 4 years ago class-wc-order-factory.php 5 years ago class-wc-order-item-coupon.php 4 years ago class-wc-order-item-fee.php 4 years ago class-wc-order-item-meta.php 4 years ago class-wc-order-item-product.php 4 years ago class-wc-order-item-shipping.php 4 years ago class-wc-order-item-tax.php 4 years ago class-wc-order-item.php 4 years ago class-wc-order-query.php 4 years ago class-wc-order-refund.php 4 years ago class-wc-order.php 4 years ago class-wc-payment-gateways.php 4 years ago class-wc-payment-tokens.php 5 years ago class-wc-post-data.php 4 years ago class-wc-post-types.php 4 years ago class-wc-privacy-background-process.php 5 years ago class-wc-privacy-erasers.php 4 years ago class-wc-privacy-exporters.php 4 years ago class-wc-privacy.php 4 years ago class-wc-product-attribute.php 4 years ago class-wc-product-download.php 4 years ago class-wc-product-external.php 5 years ago class-wc-product-factory.php 5 years ago class-wc-product-grouped.php 8 years ago class-wc-product-query.php 5 years ago class-wc-product-simple.php 5 years ago class-wc-product-variable.php 4 years ago class-wc-product-variation.php 4 years ago class-wc-query.php 4 years ago class-wc-rate-limiter.php 4 years ago class-wc-regenerate-images-request.php 5 years ago class-wc-regenerate-images.php 5 years ago class-wc-register-wp-admin-settings.php 4 years ago class-wc-rest-authentication.php 5 years ago class-wc-rest-exception.php 5 years ago class-wc-session-handler.php 4 years ago class-wc-shipping-rate.php 4 years ago class-wc-shipping-zone.php 5 years ago class-wc-shipping-zones.php 5 years ago class-wc-shipping.php 4 years ago class-wc-shortcodes.php 5 years ago class-wc-structured-data.php 5 years ago class-wc-tax.php 4 years ago class-wc-template-loader.php 4 years ago class-wc-tracker.php 4 years ago class-wc-validation.php 5 years ago class-wc-webhook.php 5 years ago class-woocommerce.php 4 years ago wc-account-functions.php 5 years ago wc-attribute-functions.php 4 years ago wc-cart-functions.php 4 years ago wc-conditional-functions.php 4 years ago wc-core-functions.php 4 years ago wc-coupon-functions.php 5 years ago wc-deprecated-functions.php 4 years ago wc-formatting-functions.php 4 years ago wc-notice-functions.php 5 years ago wc-order-functions.php 4 years ago wc-order-item-functions.php 5 years ago wc-page-functions.php 5 years ago wc-product-functions.php 4 years ago wc-rest-functions.php 4 years ago wc-stock-functions.php 4 years ago wc-template-functions.php 4 years ago wc-template-hooks.php 5 years ago wc-term-functions.php 4 years ago wc-update-functions.php 4 years ago wc-user-functions.php 4 years ago wc-webhook-functions.php 4 years ago wc-widget-functions.php 5 years ago
class-wc-cache-helper.php
359 lines
1 <?php
2 /**
3 * WC_Cache_Helper class.
4 *
5 * @package WooCommerce\Classes
6 */
7
8 defined( 'ABSPATH' ) || exit;
9
10 /**
11 * WC_Cache_Helper.
12 */
13 class WC_Cache_Helper {
14
15 /**
16 * Transients to delete on shutdown.
17 *
18 * @var array Array of transient keys.
19 */
20 private static $delete_transients = array();
21
22 /**
23 * Hook in methods.
24 */
25 public static function init() {
26 add_filter( 'nocache_headers', array( __CLASS__, 'additional_nocache_headers' ), 10 );
27 add_action( 'shutdown', array( __CLASS__, 'delete_transients_on_shutdown' ), 10 );
28 add_action( 'template_redirect', array( __CLASS__, 'geolocation_ajax_redirect' ) );
29 add_action( 'wc_ajax_update_order_review', array( __CLASS__, 'update_geolocation_hash' ), 5 );
30 add_action( 'admin_notices', array( __CLASS__, 'notices' ) );
31 add_action( 'delete_version_transients', array( __CLASS__, 'delete_version_transients' ), 10 );
32 add_action( 'wp', array( __CLASS__, 'prevent_caching' ) );
33 add_action( 'clean_term_cache', array( __CLASS__, 'clean_term_cache' ), 10, 2 );
34 add_action( 'edit_terms', array( __CLASS__, 'clean_term_cache' ), 10, 2 );
35 }
36
37 /**
38 * Set additional nocache headers.
39 *
40 * @param array $headers Header names and field values.
41 * @since 3.6.0
42 */
43 public static function additional_nocache_headers( $headers ) {
44 $agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
45
46 $set_cache = false;
47
48 /**
49 * Allow plugins to enable nocache headers. Enabled for Google weblight.
50 *
51 * @param bool $enable_nocache_headers Flag indicating whether to add nocache headers. Default: false.
52 */
53 if ( apply_filters( 'woocommerce_enable_nocache_headers', false ) ) {
54 $set_cache = true;
55 }
56
57 /**
58 * Enabled for Google weblight.
59 *
60 * @see https://support.google.com/webmasters/answer/1061943?hl=en
61 */
62 if ( false !== strpos( $agent, 'googleweblight' ) ) {
63 // no-transform: Opt-out of Google weblight. https://support.google.com/webmasters/answer/6211428?hl=en.
64 $set_cache = true;
65 }
66
67 if ( false !== strpos( $agent, 'Chrome' ) && is_cart() ) {
68 $set_cache = true;
69 }
70
71 if ( $set_cache ) {
72 $headers['Cache-Control'] = 'no-transform, no-cache, no-store, must-revalidate';
73 }
74 return $headers;
75 }
76
77 /**
78 * Add a transient to delete on shutdown.
79 *
80 * @since 3.6.0
81 * @param string|array $keys Transient key or keys.
82 */
83 public static function queue_delete_transient( $keys ) {
84 self::$delete_transients = array_unique( array_merge( is_array( $keys ) ? $keys : array( $keys ), self::$delete_transients ) );
85 }
86
87 /**
88 * Transients that don't need to be cleaned right away can be deleted on shutdown to avoid repetition.
89 *
90 * @since 3.6.0
91 */
92 public static function delete_transients_on_shutdown() {
93 if ( self::$delete_transients ) {
94 foreach ( self::$delete_transients as $key ) {
95 delete_transient( $key );
96 }
97 self::$delete_transients = array();
98 }
99 }
100
101 /**
102 * Used to clear layered nav counts based on passed attribute names.
103 *
104 * @since 3.6.0
105 * @param array $attribute_keys Attribute keys.
106 */
107 public static function invalidate_attribute_count( $attribute_keys ) {
108 if ( $attribute_keys ) {
109 foreach ( $attribute_keys as $attribute_key ) {
110 self::queue_delete_transient( 'wc_layered_nav_counts_' . $attribute_key );
111 }
112 }
113 }
114
115 /**
116 * Get prefix for use with wp_cache_set. Allows all cache in a group to be invalidated at once.
117 *
118 * @param string $group Group of cache to get.
119 * @return string
120 */
121 public static function get_cache_prefix( $group ) {
122 // Get cache key - uses cache key wc_orders_cache_prefix to invalidate when needed.
123 $prefix = wp_cache_get( 'wc_' . $group . '_cache_prefix', $group );
124
125 if ( false === $prefix ) {
126 $prefix = microtime();
127 wp_cache_set( 'wc_' . $group . '_cache_prefix', $prefix, $group );
128 }
129
130 return 'wc_cache_' . $prefix . '_';
131 }
132
133 /**
134 * Increment group cache prefix (invalidates cache).
135 *
136 * @param string $group Group of cache to clear.
137 */
138 public static function incr_cache_prefix( $group ) {
139 wc_deprecated_function( 'WC_Cache_Helper::incr_cache_prefix', '3.9.0', 'WC_Cache_Helper::invalidate_cache_group' );
140 self::invalidate_cache_group( $group );
141 }
142
143 /**
144 * Invalidate cache group.
145 *
146 * @param string $group Group of cache to clear.
147 * @since 3.9.0
148 */
149 public static function invalidate_cache_group( $group ) {
150 wp_cache_set( 'wc_' . $group . '_cache_prefix', microtime(), $group );
151 }
152
153 /**
154 * Get a hash of the customer location.
155 *
156 * @return string
157 */
158 public static function geolocation_ajax_get_location_hash() {
159 $customer = new WC_Customer( 0, true );
160 $location = array();
161 $location['country'] = $customer->get_billing_country();
162 $location['state'] = $customer->get_billing_state();
163 $location['postcode'] = $customer->get_billing_postcode();
164 $location['city'] = $customer->get_billing_city();
165 return apply_filters( 'woocommerce_geolocation_ajax_get_location_hash', substr( md5( implode( '', $location ) ), 0, 12 ), $location, $customer );
166 }
167
168 /**
169 * Prevent caching on certain pages
170 */
171 public static function prevent_caching() {
172 if ( ! is_blog_installed() ) {
173 return;
174 }
175 $page_ids = array_filter( array( wc_get_page_id( 'cart' ), wc_get_page_id( 'checkout' ), wc_get_page_id( 'myaccount' ) ) );
176
177 if ( is_page( $page_ids ) ) {
178 self::set_nocache_constants();
179 nocache_headers();
180 }
181 }
182
183 /**
184 * When using geolocation via ajax, to bust cache, redirect if the location hash does not equal the querystring.
185 *
186 * This prevents caching of the wrong data for this request.
187 */
188 public static function geolocation_ajax_redirect() {
189 if ( 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' ) && ! is_checkout() && ! is_cart() && ! is_account_page() && ! wp_doing_ajax() && empty( $_POST ) ) { // WPCS: CSRF ok, input var ok.
190 $location_hash = self::geolocation_ajax_get_location_hash();
191 $current_hash = isset( $_GET['v'] ) ? wc_clean( wp_unslash( $_GET['v'] ) ) : ''; // WPCS: sanitization ok, input var ok, CSRF ok.
192 if ( empty( $current_hash ) || $current_hash !== $location_hash ) {
193 global $wp;
194
195 $redirect_url = trailingslashit( home_url( $wp->request ) );
196
197 if ( ! empty( $_SERVER['QUERY_STRING'] ) ) { // WPCS: Input var ok.
198 $redirect_url = add_query_arg( wp_unslash( $_SERVER['QUERY_STRING'] ), '', $redirect_url ); // WPCS: sanitization ok, Input var ok.
199 }
200
201 if ( ! get_option( 'permalink_structure' ) ) {
202 $redirect_url = add_query_arg( $wp->query_string, '', $redirect_url );
203 }
204
205 $redirect_url = add_query_arg( 'v', $location_hash, remove_query_arg( 'v', $redirect_url ) );
206
207 wp_safe_redirect( esc_url_raw( $redirect_url ), 307 );
208 exit;
209 }
210 }
211 }
212
213 /**
214 * Updates the `woocommerce_geo_hash` cookie, which is used to help ensure we display
215 * the correct pricing etc to customers, according to their billing country.
216 *
217 * Note that:
218 *
219 * A) This only sets the cookie if the default customer address is set to "Geolocate (with
220 * Page Caching Support)".
221 *
222 * B) It is hooked into the `wc_ajax_update_order_review` action, which has the benefit of
223 * ensuring we update the cookie any time the billing country is changed.
224 */
225 public static function update_geolocation_hash() {
226 if ( 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' ) ) {
227 wc_setcookie( 'woocommerce_geo_hash', static::geolocation_ajax_get_location_hash(), time() + HOUR_IN_SECONDS );
228 }
229 }
230
231 /**
232 * Get transient version.
233 *
234 * When using transients with unpredictable names, e.g. those containing an md5
235 * hash in the name, we need a way to invalidate them all at once.
236 *
237 * When using default WP transients we're able to do this with a DB query to
238 * delete transients manually.
239 *
240 * With external cache however, this isn't possible. Instead, this function is used
241 * to append a unique string (based on time()) to each transient. When transients
242 * are invalidated, the transient version will increment and data will be regenerated.
243 *
244 * Raised in issue https://github.com/woocommerce/woocommerce/issues/5777.
245 * Adapted from ideas in http://tollmanz.com/invalidation-schemes/.
246 *
247 * @param string $group Name for the group of transients we need to invalidate.
248 * @param boolean $refresh true to force a new version.
249 * @return string transient version based on time(), 10 digits.
250 */
251 public static function get_transient_version( $group, $refresh = false ) {
252 $transient_name = $group . '-transient-version';
253 $transient_value = get_transient( $transient_name );
254
255 if ( false === $transient_value || true === $refresh ) {
256 $transient_value = (string) time();
257
258 set_transient( $transient_name, $transient_value );
259 }
260
261 return $transient_value;
262 }
263
264 /**
265 * Set constants to prevent caching by some plugins.
266 *
267 * @param mixed $return Value to return. Previously hooked into a filter.
268 * @return mixed
269 */
270 public static function set_nocache_constants( $return = true ) {
271 wc_maybe_define_constant( 'DONOTCACHEPAGE', true );
272 wc_maybe_define_constant( 'DONOTCACHEOBJECT', true );
273 wc_maybe_define_constant( 'DONOTCACHEDB', true );
274 return $return;
275 }
276
277 /**
278 * Notices function.
279 */
280 public static function notices() {
281 if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) {
282 return;
283 }
284
285 $config = w3_instance( 'W3_Config' );
286 $enabled = $config->get_integer( 'dbcache.enabled' );
287 $settings = array_map( 'trim', $config->get_array( 'dbcache.reject.sql' ) );
288
289 if ( $enabled && ! in_array( '_wc_session_', $settings, true ) ) {
290 ?>
291 <div class="error">
292 <p>
293 <?php
294 /* translators: 1: key 2: URL */
295 echo wp_kses_post( sprintf( __( 'In order for <strong>database caching</strong> to work with WooCommerce you must add %1$s to the "Ignored Query Strings" option in <a href="%2$s">W3 Total Cache settings</a>.', 'woocommerce' ), '<code>_wc_session_</code>', esc_url( admin_url( 'admin.php?page=w3tc_dbcache' ) ) ) );
296 ?>
297 </p>
298 </div>
299 <?php
300 }
301 }
302
303 /**
304 * Clean term caches added by WooCommerce.
305 *
306 * @since 3.3.4
307 * @param array|int $ids Array of ids or single ID to clear cache for.
308 * @param string $taxonomy Taxonomy name.
309 */
310 public static function clean_term_cache( $ids, $taxonomy ) {
311 if ( 'product_cat' === $taxonomy ) {
312 $ids = is_array( $ids ) ? $ids : array( $ids );
313
314 $clear_ids = array( 0 );
315
316 foreach ( $ids as $id ) {
317 $clear_ids[] = $id;
318 $clear_ids = array_merge( $clear_ids, get_ancestors( $id, 'product_cat', 'taxonomy' ) );
319 }
320
321 $clear_ids = array_unique( $clear_ids );
322
323 foreach ( $clear_ids as $id ) {
324 wp_cache_delete( 'product-category-hierarchy-' . $id, 'product_cat' );
325 }
326 }
327 }
328
329 /**
330 * When the transient version increases, this is used to remove all past transients to avoid filling the DB.
331 *
332 * Note; this only works on transients appended with the transient version, and when object caching is not being used.
333 *
334 * @deprecated 3.6.0 Adjusted transient usage to include versions within the transient values, making this cleanup obsolete.
335 * @since 2.3.10
336 * @param string $version Version of the transient to remove.
337 */
338 public static function delete_version_transients( $version = '' ) {
339 if ( ! wp_using_ext_object_cache() && ! empty( $version ) ) {
340 global $wpdb;
341
342 $limit = apply_filters( 'woocommerce_delete_version_transients_limit', 1000 );
343
344 if ( ! $limit ) {
345 return;
346 }
347
348 $affected = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s LIMIT %d;", '\_transient\_%' . $version, $limit ) ); // WPCS: cache ok, db call ok.
349
350 // If affected rows is equal to limit, there are more rows to delete. Delete in 30 secs.
351 if ( $affected === $limit ) {
352 wp_schedule_single_event( time() + 30, 'delete_version_transients', array( $version ) );
353 }
354 }
355 }
356 }
357
358 WC_Cache_Helper::init();
359