From fe92edf0daba7fd2af6a1fffd90b312d497bd181 Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Wed, 6 Nov 2019 11:09:06 +0000 Subject: [PATCH] [Cache service | Trunk] 1.add url in logs 2. add response in cache only for requests that return code 200 git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@57529 d315682c-612b-4755-9ff5-7f18f6832af3 --- services/cache/mecache/cache.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/cache/mecache/cache.js b/services/cache/mecache/cache.js index 918fbf29..68d1dd8d 100644 --- a/services/cache/mecache/cache.js +++ b/services/cache/mecache/cache.js @@ -12,13 +12,16 @@ let cache = (duration) => { return (req, res, next) => { let key = '__express__' + req.originalUrl || req.url + console.log(req.originalUrl || req.url); let cachedBody = mcache.get(key) if (cachedBody) { res.send(JSON.parse(cachedBody)) } else { res.sendResponse = res.send res.send = (body) => { - mcache.put(key, body, duration * 1000); + if(res.statusCode==200){ + mcache.put(key, body, duration * 1000); + } res.sendResponse(body) }; @@ -28,7 +31,7 @@ let cache = (duration) => { }; -app.get('/get',cache(20), cors(), (req, res) => { +app.get('/get',cache(30), cors(), (req, res) => { setTimeout(() => { const url = (req.query)?req.query.url:null; if (!url){