Browse Source

Add cache-control header sending in production mode

pull/26/head
Starbeamrainbowlabs 4 years ago
parent
commit
a13f813771
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
  1. 6
      logic/Actions/FetchData.php
  2. 6
      settings.default.toml

6
logic/Actions/FetchData.php

@ -79,7 +79,11 @@ class FetchData implements IAction { @@ -79,7 +79,11 @@ class FetchData implements IAction {
// 4: Send response
// TODO: Add cache-control headers here in production mode only
// Send a cache-control header, but only in production mode
if($this->settings->get("env.mode") == "production") {
header("cache-control: public, max-age=" . $this->settings->get("cache.max-age"));
}
header("content-type: application/json");
header("x-time-taken: " . PerfFormatter::format_perf_data($start_time, $start_handle, $start_encode));
echo($response);

6
settings.default.toml

@ -28,6 +28,12 @@ password = "Define_in_custom_config_file" @@ -28,6 +28,12 @@ password = "Define_in_custom_config_file"
# The default action to take if no action is specified
default-action = "fetch-data"
[cache]
# Settings that control how we request that appropriate API responses be cached.
# Note that these only affect select responses that won't change.
# Note also that cache headers are only sent in production mode - see env.mode above
max-age = 2592000 # 30 days
[data]
# Settings relating to the data returned by the API.

Loading…
Cancel
Save