您应该从创建新实例WP_REST_Response
设置Cache-Control
价值
<?php
register_rest_route(\'wp/v2\', \'/your_endpoint\', array(
\'methods\' => \'GET\',
\'callback\' => \'function_callback\',
));
function function_callback($data) {
$response = array(
1,2,3,4,5,6,7,8
);
$result = new WP_REST_Response($response, 200);
// Set headers.
$result->set_headers(array(\'Cache-Control\' => \'max-age=3600\'));
return $result;
}
Click here 获取有关指令的更多信息。