NodeJS - 发布数据缓存在请求正文中

时间:2014-06-11 07:17:28

标签: node.js express mean-stack

我有两个节点服务器,其中节点server2(端口3001)从节点server1接收请求(在端口3000上运行)。

当我在server1中绑定数据并对server2进行后调用时,server2始终缓存在先前调用中维护的旧数据。

   For ex : Old Post data is     { emailid : 'xxxx',
                          name : 'XXXX',
                          records : [0,1,2,3,4]
                          } 

      If Next POST data from server1 is       { emailid : 'xxxx',
                                            name : 'XXXX',
                                            records : [5,6]
                                          } 
      Then Server2 recieves these data as      { emailid : 'xxxx',
                                            name : 'XXXX',
                                            records : [5,6,2,3,4]
                                          } 

     I dont want the old records 2,3,4 in req.body.records array .. but it is cached. 

     Could you please help me how to remove the caching of the old data in request body container.


    Please look at my server1 code where i make REST calls using node request module: 

Server1 comfiguaraton -

app.configure(function() {
    // The cookieParser should be above session
     app.use(express.cookieParser());
    app.use(express.session({secret:'ayer'}));

    // Request body parsing middleware should be above methodOverride
    app.use(express.urlencoded());
    app.use(express.json());
 //      app.use(expressValidator());
    app.use(express.methodOverride());

    // Routes should be at the last
    app.use(app.router);

// Setting the fav icon and static folder
//app.use(express.favicon());
app.use(express.favicon(__dirname + '/public/favicon.ico'));
//app.use('/', express.static(config.root + '/public'));

 });

对server2进行rest API调用的方法     exports.docleansematch = function(req,res,sessionStore){

/*setting up user verification request options*/
var Options = {
    uri: 'http:localhost:3001/docleansematch',
    method: 'POST',
    json:true,
    proxy: config.app.proxy, // calling to internal server
    headers: {'Content-Type':'application/x-www-form-urlencoded'
              },
    form : req.body

};
request.post(Options,function(err,extResponse,extResponseBody)
{
    var data = {};
    if(err)
    {
        log.error('Error in App layer : ',err);
        data.status = 2;
    }
    else
    {
        data.status = extResponseBody.status;

    }
    res.jsonp(data);

});

};

Server2接收请求数据的方法:

app.post('/docleansematch',function(req,res){


    log.info('Cached Number of records - '+ req.body.records.length);


    res.json({status:3}); 
}

1 个答案:

答案 0 :(得分:1)

在我的进一步分析中,Server1在请求表单提交中发送值时维护一个缓存。

var Options = {
uri: 'http:localhost:3001/docleansematch',
method: 'POST',
json:true,
proxy: config.app.proxy, // calling to internal server
headers: {'Content-Type':'application/x-www-form-urlencoded'
          },
form : req.body

 };
 request.post(Options,function(err,extResponse,extResponseBody)
{
var data = {};
if(err)
{
    log.error('Error in App layer : ',err);
    data.status = 2;
}
else
{
    data.status = extResponseBody.status;

}
res.jsonp(data);

});

};

Server1 - > form:req.body缓存在post请求中发送的值,并在subsequest上调用后,在表单中附加旧数据..以便server2接收带有附加数据的all。

你知道如何在nodejs的请求模块中清除缓存吗?