Add short-term caching header to list-devices and list-devices-near.

This commit is contained in:
Starbeamrainbowlabs 2019-10-10 21:25:40 +01:00
parent ff1d784e6a
commit 209fcd7926
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
4 changed files with 11 additions and 4 deletions

View file

@ -83,8 +83,11 @@ class ListDevices implements IAction {
// 4: Send response // 4: Send response
// Don't a cache control header, because new devices might get added at any time // Don't cache for ages, because new devices might get added at any time
// TODO: Investigate adding a short-term (~10mins?) cache-control header here // FUTURE: Move last-seen to a different API call if caching becomes critically important?
if($this->settings->get("env.mode") == "production") {
header("cache-control: public, max-age=" . $this->settings->get("cache.max-age-supershort"));
}
header("content-length: " . strlen($response)); header("content-length: " . strlen($response));
header("content-type: $response_type"); header("content-type: $response_type");

View file

@ -83,8 +83,9 @@ class ListDevicesNear implements IAction {
// 4: Send response // 4: Send response
// Send a cache-control header, but only in production mode // Send a cache-control header, but only in production mode
// FUTURE: Move last-seen to a different API call if caching becomes critically important?
if($this->settings->get("env.mode") == "production") { if($this->settings->get("env.mode") == "production") {
header("cache-control: public, max-age=" . $this->settings->get("cache.max-age")); header("cache-control: public, max-age=" . $this->settings->get("cache.max-age-supershort"));
} }
header("content-length: " . strlen($response)); header("content-length: " . strlen($response));

View file

@ -34,6 +34,9 @@ default-action = "index"
# Note also that cache headers are only sent in production mode - see env.mode above # Note also that cache headers are only sent in production mode - see env.mode above
max-age = 2592000 # 30 days max-age = 2592000 # 30 days
# The max-age for time-sensitive data (e.g. last_seen values). Defaults to 30 seconds, which should yield some benefit).
max-age-supershort = 30 # 30 seconds
[data] [data]
# Settings relating to the data returned by the API. # Settings relating to the data returned by the API.