Some caching fixes
This commit is contained in:
parent
402682bdea
commit
e772a5b596
14
server.js
14
server.js
@ -34,6 +34,7 @@ app.get('/weather', (req, res) => {
|
|||||||
|
|
||||||
weather.doGetOpenWeather(req.query.ll)
|
weather.doGetOpenWeather(req.query.ll)
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
|
res.set('Cache-Control', 'public, max-age=1800');
|
||||||
res.send(d);
|
res.send(d);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
@ -54,6 +55,7 @@ app.get('/forecast', (req, res) => {
|
|||||||
|
|
||||||
weather.doGetFullForcast(req.query.ll)
|
weather.doGetFullForcast(req.query.ll)
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
|
res.set('Cache-Control', 'public, max-age=1800');
|
||||||
res.send(d);
|
res.send(d);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
@ -73,6 +75,7 @@ app.get('/weatheralert', cache('15 minutes'), (req, res) => {
|
|||||||
// doGetDarkSkyWeather
|
// doGetDarkSkyWeather
|
||||||
weather.doGetDarkSkyWeather(req.query.ll)
|
weather.doGetDarkSkyWeather(req.query.ll)
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
|
res.set('Cache-Control', 'public, max-age=1800');
|
||||||
res.send(d);
|
res.send(d);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
@ -95,6 +98,7 @@ app.get('/fsexplore', cache('15 minutes'), (req, res) => {
|
|||||||
console.log('req.query',req.query);
|
console.log('req.query',req.query);
|
||||||
foursquare.doGetFourSquareExplore(ll, limit, section, query)
|
foursquare.doGetFourSquareExplore(ll, limit, section, query)
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
|
res.set('Cache-Control', 'public, max-age=900');
|
||||||
res.send(d);
|
res.send(d);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
@ -109,10 +113,11 @@ app.get('/fsexplore', cache('15 minutes'), (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/rightbyme', cache('15 minutes'), (req, res) => {
|
app.get('/rightbyme', cache('86400 seconds'), (req, res) => {
|
||||||
if (req.query.hasOwnProperty('ll'))
|
if (req.query.hasOwnProperty('ll'))
|
||||||
rightbyme.doGetRightByMe(req.query.ll)
|
rightbyme.doGetRightByMe(req.query.ll)
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
|
res.set('Cache-Control', 'public, max-age=86400');
|
||||||
res.send(d);
|
res.send(d);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
@ -130,6 +135,7 @@ app.get('/nearbydetail', cache('15 minutes'), (req, res) => {
|
|||||||
if (req.query.hasOwnProperty('id'))
|
if (req.query.hasOwnProperty('id'))
|
||||||
rightbyme.doGetMoreDetail(req.query.id)
|
rightbyme.doGetMoreDetail(req.query.id)
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
|
res.set('Cache-Control', 'public, max-age=900');
|
||||||
res.send(d);
|
res.send(d);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
@ -145,6 +151,7 @@ app.get('/nearbydetail', cache('15 minutes'), (req, res) => {
|
|||||||
|
|
||||||
app.get('/news', cache('15 minutes'), (req, res) => {
|
app.get('/news', cache('15 minutes'), (req, res) => {
|
||||||
euronews.getEuroNews().then((d) => {
|
euronews.getEuroNews().then((d) => {
|
||||||
|
res.set('Cache-Control', 'public, max-age=1800');
|
||||||
res.send(d);
|
res.send(d);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
if (e.message === '304:Not changed') {
|
if (e.message === '304:Not changed') {
|
||||||
@ -164,6 +171,7 @@ app.get('/article', cache('1 hour'), (req, res) => {
|
|||||||
|
|
||||||
euronews.getArticle(req.query.guid)
|
euronews.getArticle(req.query.guid)
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
|
res.set('Cache-Control', 'public, max-age=3600');
|
||||||
res.send(d);
|
res.send(d);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
@ -180,6 +188,7 @@ app.get('/article', cache('1 hour'), (req, res) => {
|
|||||||
app.get('/agenda', cache('15 minutes'), (req, res) => {
|
app.get('/agenda', cache('15 minutes'), (req, res) => {
|
||||||
agenda.doTodaysAgenda()
|
agenda.doTodaysAgenda()
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
|
res.set('Cache-Control', 'public, max-age=900');
|
||||||
res.send(d);
|
res.send(d);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
@ -193,6 +202,7 @@ app.get('/oldtraffic', cache('5 minutes'), (req, res) => {
|
|||||||
|
|
||||||
directions.getTraffic(req.query.olat, req.query.olon, req.query.dlat, req.query.dlon)
|
directions.getTraffic(req.query.olat, req.query.olon, req.query.dlat, req.query.dlon)
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
|
res.set('Cache-Control', 'public, max-age=900');
|
||||||
res.send(d);
|
res.send(d);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
@ -211,6 +221,7 @@ app.get('/incidents', cache('5 minutes'), (req, res) => {
|
|||||||
directions.getIncidents()
|
directions.getIncidents()
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
logger.debug(d);
|
logger.debug(d);
|
||||||
|
res.set('Cache-Control', 'public, max-age=300');
|
||||||
res.send(d);
|
res.send(d);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
@ -225,6 +236,7 @@ app.get('/traffic', cache('5 minutes'), asyncMiddleware(async (req, res, next) =
|
|||||||
|
|
||||||
await directions.doGetEstDirectionsWithIncidents(req.query.olat, req.query.olon, req.query.dlat, req.query.dlon).then((b) => {
|
await directions.doGetEstDirectionsWithIncidents(req.query.olat, req.query.olon, req.query.dlat, req.query.dlon).then((b) => {
|
||||||
//logger.debug('b', b);
|
//logger.debug('b', b);
|
||||||
|
res.set('Cache-Control', 'public, max-age=300');
|
||||||
res.send(b);
|
res.send(b);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
const CACHE_VERSION = { 'version': '0.0.885' };
|
const CACHE_VERSION = { 'version': '0.0.887' };
|
||||||
const PRECACHE = `jubileeData-${CACHE_VERSION.version}`;
|
const PRECACHE = `jubileeData-${CACHE_VERSION.version}`;
|
||||||
const RUNTIME = 'runtime';
|
const RUNTIME = 'runtime';
|
||||||
|
|
||||||
@ -124,7 +124,6 @@ self.addEventListener('fetch', event => {
|
|||||||
);
|
);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
console.log('Req', event.request.url);
|
|
||||||
if (event.request.url.startsWith(self.location.origin)) {
|
if (event.request.url.startsWith(self.location.origin)) {
|
||||||
console.log('One of our requests..');
|
console.log('One of our requests..');
|
||||||
|
|
||||||
@ -146,6 +145,8 @@ self.addEventListener('fetch', event => {
|
|||||||
event.respondWith(
|
event.respondWith(
|
||||||
caches.open(RUNTIME).then(function(cache) {
|
caches.open(RUNTIME).then(function(cache) {
|
||||||
return cache.match(event.request).then(function (response) {
|
return cache.match(event.request).then(function (response) {
|
||||||
|
console.log('£', response);
|
||||||
|
|
||||||
return response || fetch(event.request).then(function(response) {
|
return response || fetch(event.request).then(function(response) {
|
||||||
cache.put(event.request, response.clone());
|
cache.put(event.request, response.clone());
|
||||||
|
|
||||||
@ -176,18 +177,3 @@ self.addEventListener('fetch', event => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
self.addEventListener('fetch', function(event) {
|
|
||||||
event.respondWith(
|
|
||||||
caches.open('mysite-dynamic').then(function(cache) {
|
|
||||||
return cache.match(event.request).then(function (response) {
|
|
||||||
return response || fetch(event.request).then(function(response) {
|
|
||||||
cache.put(event.request, response.clone());
|
|
||||||
return response;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
Loading…
Reference in New Issue
Block a user