Commit d0547fae05 for woocommerce

commit d0547fae058c987af38bee915e5d3ca82c9ae385
Author: Néstor Soriano <konamiman@konamiman.com>
Date:   Wed Jan 21 09:09:10 2026 +0100

    Add caching for the continents REST API endpoints (#62856)

diff --git a/plugins/woocommerce/changelog/pr-62856 b/plugins/woocommerce/changelog/pr-62856
new file mode 100644
index 0000000000..d48caef8e7
--- /dev/null
+++ b/plugins/woocommerce/changelog/pr-62856
@@ -0,0 +1,4 @@
+Significance: minor
+Type: update
+
+Add caching for the continents REST API endpoints
diff --git a/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-data-continents-controller.php b/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-data-continents-controller.php
index 357777dcf3..1437818137 100644
--- a/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-data-continents-controller.php
+++ b/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-data-continents-controller.php
@@ -8,6 +8,8 @@
  * @since   3.5.0
  */

+use Automattic\WooCommerce\Internal\Traits\RestApiCache;
+
 defined( 'ABSPATH' ) || exit;

 /**
@@ -18,6 +20,8 @@ defined( 'ABSPATH' ) || exit;
  */
 class WC_REST_Data_Continents_Controller extends WC_REST_Data_Controller {

+	use RestApiCache;
+
 	/**
 	 * Endpoint namespace.
 	 *
@@ -32,6 +36,13 @@ class WC_REST_Data_Continents_Controller extends WC_REST_Data_Controller {
 	 */
 	protected $rest_base = 'data/continents';

+	/**
+	 * Constructor.
+	 */
+	public function __construct() {
+		$this->initialize_rest_api_cache();
+	}
+
 	/**
 	 * Register routes.
 	 *
@@ -44,7 +55,7 @@ class WC_REST_Data_Continents_Controller extends WC_REST_Data_Controller {
 			array(
 				array(
 					'methods'             => WP_REST_Server::READABLE,
-					'callback'            => array( $this, 'get_items' ),
+					'callback'            => $this->with_cache( array( $this, 'get_items' ) ),
 					'permission_callback' => array( $this, 'get_items_permissions_check' ),
 				),
 				'schema' => array( $this, 'get_public_item_schema' ),
@@ -56,7 +67,7 @@ class WC_REST_Data_Continents_Controller extends WC_REST_Data_Controller {
 			array(
 				array(
 					'methods'             => WP_REST_Server::READABLE,
-					'callback'            => array( $this, 'get_item' ),
+					'callback'            => $this->with_cache( array( $this, 'get_item' ) ),
 					'permission_callback' => array( $this, 'get_items_permissions_check' ),
 					'args'                => array(
 						'continent' => array(
@@ -359,4 +370,70 @@ class WC_REST_Data_Continents_Controller extends WC_REST_Data_Controller {

 		return $this->add_additional_fields_schema( $schema );
 	}
+
+	/**
+	 * Get the default entity type for response caching.
+	 *
+	 * @return string|null The entity type.
+	 */
+	protected function get_default_response_entity_type(): ?string {
+		return 'continent';
+	}
+
+	/**
+	 * Get the files relevant to response caching.
+	 *
+	 * @param WP_REST_Request<array<string, mixed>> $request     The request object.
+	 * @param string|null                           $endpoint_id Optional endpoint identifier.
+	 * @return array Array of file paths to track for cache invalidation.
+	 */
+	protected function get_files_relevant_to_response_caching( WP_REST_Request $request, ?string $endpoint_id = null ): array { // phpcs:ignore Squiz.Commenting.FunctionComment.IncorrectTypeHint
+		return array(
+			'i18n/continents.php',
+			'i18n/countries.php',
+			'i18n/states.php',
+			'i18n/locale-info.php',
+		);
+	}
+
+	/**
+	 * Get the hooks relevant to response caching.
+	 *
+	 * @param WP_REST_Request<array<string, mixed>> $request     The request object.
+	 * @param string|null                           $endpoint_id Optional endpoint identifier.
+	 * @return array Array of hook names to track for cache invalidation.
+	 */
+	protected function get_hooks_relevant_to_caching( WP_REST_Request $request, ?string $endpoint_id = null ): array { // phpcs:ignore Squiz.Commenting.FunctionComment.IncorrectTypeHint
+		return array(
+			'woocommerce_continents',
+			'woocommerce_countries',
+			'woocommerce_states',
+			'woocommerce_rest_prepare_data_continent',
+		);
+	}
+
+	/**
+	 * Whether the response cache should vary by user.
+	 *
+	 * @param WP_REST_Request<array<string, mixed>> $request     The request object.
+	 * @param string|null                           $endpoint_id Optional endpoint identifier.
+	 * @return bool False since continent data doesn't vary by user.
+	 */
+	protected function response_cache_vary_by_user( WP_REST_Request $request, ?string $endpoint_id = null ): bool { // phpcs:ignore Squiz.Commenting.FunctionComment.IncorrectTypeHint
+		return false;
+	}
+
+	/**
+	 * Extract entity IDs from response data.
+	 *
+	 * Continents don't have entity IDs, cache invalidation is file-based.
+	 *
+	 * @param array                                 $response_data Response data.
+	 * @param WP_REST_Request<array<string, mixed>> $request       The request object.
+	 * @param string|null                           $endpoint_id   Optional endpoint identifier.
+	 * @return array Empty array since continents don't have entity IDs.
+	 */
+	protected function extract_entity_ids_from_response( array $response_data, WP_REST_Request $request, ?string $endpoint_id = null ): array { // phpcs:ignore Squiz.Commenting.FunctionComment.IncorrectTypeHint
+		return array();
+	}
 }