Skip to content

Commit

Permalink
add cache-control to LitCalMetadata.php
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRDOrazio committed Feb 6, 2022
1 parent 9cc5b74 commit 3d77f60
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion LitCalMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
header( 'Access-Control-Allow-Origin: *' );
}
header( 'Access-Control-Max-Age: 86400' ); // cache for 1 day
header( 'Cache-Control: must-revalidate, max-age=259200' );
header( 'Content-Type: application/json' );

//National Calendars are defined in the LitCalAPI engine itself,
Expand Down Expand Up @@ -37,12 +38,20 @@
}
}

echo json_encode( [
$response = json_encode( [
"LitCalMetadata" => [
"NationalCalendars" => $nationalCalendars,
"DiocesanCalendars" => $diocesanCalendars
],
], JSON_PRETTY_PRINT );
$responseHash = md5( $response );
header("Etag: \"{$responseHash}\"");
if (!empty( $_SERVER['HTTP_IF_NONE_MATCH'] ) && $_SERVER['HTTP_IF_NONE_MATCH'] === $responseHash) {
header( $_SERVER[ "SERVER_PROTOCOL" ] . " 304 Not Modified" );
header('Content-Length: 0');
} else {
echo $response;
}
} else {
http_response_code(503);
}
Expand Down

0 comments on commit 3d77f60

Please sign in to comment.