通过Heroku阻止Node.JS中的HTTP请求缓存

时间:2015-11-09 22:08:43

标签: node.js caching heroku

我正在构建一个松散的Web钩子,它定期从/ r / GameDeals获取最高销售额并将它们发布到松弛状态。然而,在过去的一周里,这些请求与前一天一样返回了同一个机构。我不是将数据存储在任何地方,只是获取它,解析它,然后POST到松弛。这是我的代码:

request('https://www.reddit.com/r/GameDeals.json', function (error, response, body) {
 if (!error && response.statusCode == 200) {
   console.log('Successfully retrieved /r/GameDeals');
   var bodyJSON = JSON.parse(body);
   var toSend = "Here are today's sales: \n";

   // grab the top 5 deals from GameDeals
   for (var i=0;i<5;i++)
     toSend += postString(bodyJSON['data']['children'][i]);
   sendToSlack(toSend);
 } else
   console.log('ERROR: ' + error);
});

function sendToSlack(toSend) {
  var text = { text: toSend };
  request.post('https://hooks.slack.com/services/AAAAAA/BBBBBBB/CCCCCC',
             {body:JSON.stringify(text)});
  console.log("POSTed: " + toSend);
}

查看heroku日志的最后两天,它显示相同的POSTed:

2015-11-08T17:05:00.130635+00:00 app[web.1]: Performing daily sales check
2015-11-08T17:05:00.138196+00:00 app[web.1]: Checking sales for games in Firebase
2015-11-08T17:05:00.718358+00:00 app[web.1]: Successfully retrieved /r/GameDeals
2015-11-08T17:05:00.722763+00:00 app[web.1]: POSTed: Here are today's sales:
2015-11-08T17:05:00.722766+00:00 app[web.1]: - [GOG.com] BIG FALL SALE (Day 5) -- 2 new bundles (Settler's Pack &amp; Shots Fired), with new daily deals incl. Runaway series at 80% off; Syberia, Far Cry, LEGO Harry Potter games at 75% off and more -- DRM-free [<http://www.gog.com/|link>]
2015-11-08T17:05:00.722768+00:00 app[web.1]: - [Best Buy] Save $25 on a select game when you purchase Fallout 4, Tomb Raider or Call of Duty: Black Ops III [<http://www.bestbuy.com/site/offer/139091/pcmcat748300699145.c?id=pcmcat748300699145&amp;|link>]
2015-11-08T17:05:00.722769+00:00 app[web.1]: - [Target] Buy two get one for free has finally arrived! (3 for the price of 2) [<http://weeklyad.target.com/promotions?code=Target-151108&amp;page=1|link>]
2015-11-08T17:05:00.722770+00:00 app[web.1]: - [Best Buy] Buy a PS4 Console Bundle and get Fallout 4 and a Controller Charging Station for Free [<http://www.bestbuy.com/site/promo/ps4-offer-147984?|link>]
2015-11-08T17:05:00.722771+00:00 app[web.1]: - [GamersGate] Rocksmith 2014 ($10/€7.50/£6 | 75% off) | Steam, Worldwide [<http://www.gamersgate.com/DD-RS2014/rocksmith-2014|link>].1]: State changed from starting to up

...

2015-11-09T17:05:00.301154+00:00 app[web.1]: Performing daily sales check
2015-11-09T17:05:00.316703+00:00 app[web.1]: Checking sales for games in Firebase
2015-11-09T17:05:10.520064+00:00 app[web.1]: POSTed: Here are today's sales:
2015-11-09T17:05:10.520070+00:00 app[web.1]: - [GOG.com] BIG FALL SALE (Day 5) -- 2 new bundles (Settler's Pack &amp; Shots Fired), with new daily deals incl. Runaway series at 80% off; Syberia, Far Cry, LEGO Harry Potter games at 75% off and more -- DRM-free [<http://www.gog.com/|link>]
2015-11-09T17:05:10.520072+00:00 app[web.1]: - [Best Buy] Save $25 on a select game when you purchase Fallout 4, Tomb Raider or Call of Duty: Black Ops III [<http://www.bestbuy.com/site/offer/139091/pcmcat748300699145.c?id=pcmcat748300699145&amp;|link>]
2015-11-09T17:05:10.520073+00:00 app[web.1]: - [Target] Buy two get one for free has finally arrived! (3 for the price of 2) [<http://weeklyad.target.com/promotions?code=Target-151108&amp;page=1|link>]
2015-11-09T17:05:10.520074+00:00 app[web.1]: - [Best Buy] Buy a PS4 Console Bundle and get Fallout 4 and a Controller Charging Station for Free [<http://www.bestbuy.com/site/promo/ps4-offer-147984?|link>]
2015-11-09T17:05:10.520076+00:00 app[web.1]:
2015-11-09T17:05:10.520075+00:00 app[web.1]: - [GamersGate] Rocksmith 2014 ($10/€7.50/£6 | 75% off) | Steam, Worldwide [<http://www.gamersgate.com/DD-RS2014/rocksmith-2014|link>]
2015-11-09T17:05:10.511322+00:00 app[web.1]: Successfully retrieved /r/GameDeals

我不确定这是否是Heroku缓存对我的请求的响应,只是让我回到最后一次收到的同一个身体或什么。我的机器人有另一个功能,它允许它查找特定的游戏和POST回来松弛该特定游戏是否在售。但是,当我这样做时,似乎重置了这个缓存过程,第二天就会返回新的查询。此函数还使用request npm。

0 个答案:

没有答案