Browse Source

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

bugfix/performance
Starbeamrainbowlabs 3 years ago
parent
commit
209fcd7926
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
  1. 2
      README.md
  2. 7
      logic/Actions/ListDevices.php
  3. 3
      logic/Actions/ListDevicesNear.php
  4. 3
      settings.default.toml

2
README.md

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
This project contains the web interface for the ConnectedHumber sensor system. Despite being called _Air Quality Web_, it is designed to display any kind of sensor data - not just air quality sensor readings.
It is composed of 2 parts:
It is composed of 2 parts:
- A PHP-based JSON API server (entry point: api.php) that's backed by a MariaDB server
- A Javascript client application that runs in the browser

7
logic/Actions/ListDevices.php

@ -83,8 +83,11 @@ class ListDevices implements IAction { @@ -83,8 +83,11 @@ class ListDevices implements IAction {
// 4: Send response
// Don't a cache control header, because new devices might get added at any time
// TODO: Investigate adding a short-term (~10mins?) cache-control header here
// Don't cache for ages, because new devices might get added at any time
// 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-type: $response_type");

3
logic/Actions/ListDevicesNear.php

@ -83,8 +83,9 @@ class ListDevicesNear implements IAction { @@ -83,8 +83,9 @@ class ListDevicesNear implements IAction {
// 4: Send response
// 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") {
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));

3
settings.default.toml

@ -34,6 +34,9 @@ default-action = "index" @@ -34,6 +34,9 @@ default-action = "index"
# Note also that cache headers are only sent in production mode - see env.mode above
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]
# Settings relating to the data returned by the API.

Loading…
Cancel
Save