开发者

Connect session middleware - regenerate vs reload

I am trying to get a hang of Connect's Session middleware, and I would like to know the difference between: Session.rege开发者_JAVA技巧nerate() vs Session.reload().

Specifically, I checked the docs, and no explanation was given about what session reload actually does. Similarly, I am also confused about Session.save() method. Any help greatly appreciated!


Comparing the source code for the 2 functions:

store.js

Store.prototype.regenerate = function(req, fn){
  var self = this;
  this.destroy(req.sessionID, function(err){
    self.generate(req);
    fn(err);
  });
};

and

session.js

defineMethod(Session.prototype, 'reload', function reload(fn) {
  var req = this.req
    , store = this.req.sessionStore;
  store.get(this.id, function(err, sess){
    if (err) return fn(err);
    if (!sess) return fn(new Error('failed to load session'));
    store.createSession(req, sess);
    fn();
  });
  return this;
});

I read it as "get the session if it exists or create one" vs "destroy the previous and give me a new one".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜