Skip to content

Commit b773412

Browse files
committed
Update cache-control headers to set browser cache to 5 seconds for robots.txt and REST API responses, facilitating cache validation testing.
1 parent 199db1a commit b773412

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

default-cache-control.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,16 @@ function cache_control_send_post_type_archive_headers() {
214214
* @return void
215215
*/
216216
function cache_control_send_robots_headers() {
217-
// 1 hour cache for robots.txt
218217
$s_maxage = \HOUR_IN_SECONDS;
219218

219+
// Set browser cache to 5 seconds to enable cache validation testing via HTTP headers
220+
$max_age = 5;
221+
220222
// Send cache headers directly
221223
header(
222224
sprintf(
223225
'Cache-Control: public, max-age=%d, s-maxage=%d, stale-while-revalidate=%d, stale-if-error=%d',
224-
$s_maxage,
226+
$max_age,
225227
$s_maxage,
226228
$s_maxage * 5,
227229
$s_maxage * 3
@@ -286,11 +288,14 @@ function cache_control_send_rest_api_headers( $result, $server, $request ) {
286288

287289
$s_maxage = \HOUR_IN_SECONDS;
288290

291+
// Set browser cache to 5 seconds to enable cache validation testing via HTTP headers
292+
$max_age = 5;
293+
289294
$result->header(
290295
'Cache-Control',
291296
sprintf(
292297
'public, max-age=%d, s-maxage=%d, stale-while-revalidate=%d, stale-if-error=%d',
293-
$s_maxage,
298+
$max_age,
294299
$s_maxage,
295300
$s_maxage * 5,
296301
$s_maxage * 3

0 commit comments

Comments
 (0)