Will http caching using WP_REST_Response() be specific to the data that is requested?

Question

If I have data being requested, and the response is dependent on the data requested, would the following sample code cache all responses the same, or would it somehow know "you requested a response for $data with X values, so we are only caching a response for data with X values?

Basically my callback function should be returning the same response only if the same data is requested.

Sample code:

register_rest_route('wp/v2', '/my_endpoint', array(
'methods' => 'GET',
'callback' => 'function_callback',
));

function function_callback($data) {

// this response would be different depending on the $data requested
$response = functionThatUtilizesInputData($data);

$result = new WP_REST_Response($response, 200);

// Set headers.
$result->set_headers(array('Cache-Control' => 'max-age=3600'));

return $result;
}
0
Best Dev Tutorials 2 months 0 Answers 12 views 0

Leave an answer