diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-04-04 23:03:39 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-04-04 23:03:39 +0200 |
commit | 72cc6f1570a2a829933688142ba3a2f607b13f44 (patch) | |
tree | 730e3b3e7875a3b22a777ffa4514c9c8d09eb0d8 /modules | |
parent | ef4353f11e98305d1906c075bdaacbb32dfb2024 (diff) |
quotesgrab: cache results briefly
Diffstat (limited to 'modules')
-rw-r--r-- | modules/quotesgrab/quotesgrab.js | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/modules/quotesgrab/quotesgrab.js b/modules/quotesgrab/quotesgrab.js index 37f44e6..c540d3a 100644 --- a/modules/quotesgrab/quotesgrab.js +++ b/modules/quotesgrab/quotesgrab.js @@ -57,11 +57,19 @@ function getquoteslist(cb){ }); } +var cache=null,cachedate=null; + module.exports=function(app,io,moddir){ app.get("/quotes",function(req,res){ res.set("Content-Type", "text/json"); - getquoteslist(function(obj){ - res.end(JSON.stringify(obj)); - }); + if(cache!=null&&new Date()-cachedate<60*1000){ + res.end(cache); + } else { + getquoteslist(function(obj){ + cache=JSON.stringify(obj); + cachedate=new Date(); + res.end(cache); + }); + } }); }; |