diff --git a/package-lock.json b/package-lock.json index 894b5fa..b5800d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.0", "dependencies": { "@observablehq/plot": "^0.6.1", + "apicache": "^1.6.3", "async": "^3.2.0", "cookie-parser": "~1.4.4", "d3": "^7.8.0", @@ -120,6 +121,14 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, + "node_modules/apicache": { + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/apicache/-/apicache-1.6.3.tgz", + "integrity": "sha512-jS3VfUFpQ9BesFQZcdd1vVYg3ZsO2kGPmTJHqycIYPAQs54r74CRiyj8DuzJpwzLwIfCBYzh4dy9Jt8xYbo27w==", + "engines": { + "node": ">=8" + } + }, "node_modules/array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", @@ -1764,6 +1773,11 @@ } } }, + "apicache": { + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/apicache/-/apicache-1.6.3.tgz", + "integrity": "sha512-jS3VfUFpQ9BesFQZcdd1vVYg3ZsO2kGPmTJHqycIYPAQs54r74CRiyj8DuzJpwzLwIfCBYzh4dy9Jt8xYbo27w==" + }, "array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", diff --git a/package.json b/package.json index 2def05d..8c63bc4 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ }, "dependencies": { "@observablehq/plot": "^0.6.1", + "apicache": "^1.6.3", "async": "^3.2.0", "cookie-parser": "~1.4.4", "d3": "^7.8.0", diff --git a/routes/index.js b/routes/index.js index 06a0a31..11643cb 100644 --- a/routes/index.js +++ b/routes/index.js @@ -2,10 +2,13 @@ var express = require('express'); var router = express.Router(); var async = require('async'); var stats = require('../modules/data'); +var apicache = require('apicache'); const { stat } = require('fs'); const APP_TITLE = 'HAM Dashboard'; +let cache = apicache.middleware; + let data = { datafreshness: 0, dateoflastrefresh: "2000-01-01", @@ -43,7 +46,7 @@ router.get('/:env', function(req, res, next) { }); /* GET home page. */ -router.get('/', function(req, res, next) { +router.get('/', cache('6 hours'), function(req, res, next) { async.parallel({ objectStats: stats.getObjectStats,