From cac44d718e5757bbed7973dc8d88fcc1583f9656 Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Fri, 26 Jun 2020 14:44:28 +0000 Subject: [PATCH] Cache service: -change console.debug to log -mv resetAtMidnight inside app.listen git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@59002 d315682c-612b-4755-9ff5-7f18f6832af3 --- services/cache/mecache/cache.js | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/services/cache/mecache/cache.js b/services/cache/mecache/cache.js index 435be2d5..d99b977a 100644 --- a/services/cache/mecache/cache.js +++ b/services/cache/mecache/cache.js @@ -41,7 +41,7 @@ let cache = () => { return (req, res, next) => { if(req.query.url) { if(mcache.size() > cacheMaxSize){ - console.debug("Max cache size reached!"+cacheMaxSize); + console.log("Max cache size reached!"+cacheMaxSize); clearCache(); } let key = '__express__' + req.query.url; @@ -129,33 +129,14 @@ app.get('/get', cache(), cors(), (req, res) => { }); -app.get('/get', cache(30), cors(), (req, res) => { - setTimeout(() => { - const url = (req.query) ? req.query.url : null; - if (!url) { - res.status(404).send(getResponse(404, "Not Found ")) //not found - } else { - request.get(url, function (err, response) { - // res.header("Access-Control-Allow-Origin", "http://localhost:3000"); - res.header("Access-Control-Allow-Headers", "Origin, Content-Type, Content-Length"); - res.header("Access-Control-Allow-Methods", "GET, OPTIONS"); - res.header("Access-Control-Allow-Methods", "GET, OPTIONS"); - res.header("Content-Type", "application/json"); - if (!response && err) { - res.status(500).send(getResponse(500, "An error occurred for " + url)) - } else { - res.status(response.status).send(response.body); - } - }) - } - }) -}); app.use((req, res) => { res.status(404).send(getResponse(404, "Not Found")); //not found }); app.listen((process.env.PORT) ? process.env.PORT : 3000, function () { - console.log(`Example app listening on port ${process.env.PORT}!`) + console.log(`Example app listening on port ${(process.env.PORT) ? process.env.PORT : 3000}!`) + //run the timer + resetAtMidnight(); }); function getResponse(code, message) { @@ -166,7 +147,7 @@ function getResponse(code, message) { } function clearCache(){ - console.debug("cache is cleared!"); + console.log("cache is cleared!"); mcache.clear(); entries.set(mcache.size()); } @@ -179,10 +160,8 @@ function checkForLongCachedRequests(url){ }); return long; } -//run the timer -resetAtMidnight(); function resetAtMidnight() { - console.debug("Run Reset timer"); + console.log("Run Reset timer"); var now = new Date(); var night = new Date( now.getFullYear(),