mirror of
https://github.com/ConnectedHumber/Air-Quality-Web
synced 2024-12-21 10:25:00 +00:00
Add short-term caching header to list-devices and list-devices-near.
This commit is contained in:
parent
ff1d784e6a
commit
209fcd7926
4 changed files with 11 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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…
Reference in a new issue