summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-04-04 23:03:39 +0200
committertomsmeding <tom.smeding@gmail.com>2017-04-04 23:03:39 +0200
commit72cc6f1570a2a829933688142ba3a2f607b13f44 (patch)
tree730e3b3e7875a3b22a777ffa4514c9c8d09eb0d8 /modules
parentef4353f11e98305d1906c075bdaacbb32dfb2024 (diff)
quotesgrab: cache results briefly
Diffstat (limited to 'modules')
-rw-r--r--modules/quotesgrab/quotesgrab.js14
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);
+ });
+ }
});
};