Connect session middleware - regenerate vs. reload
Asked Answered
V

1

5

I am trying to get a hang of Connect's Session middleware, and I would like to know the difference between: Session.regenerate() 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!

Vast answered 17/5, 2011 at 16:25 Comment(0)
G
7

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".

Gilmagilman answered 17/5, 2011 at 16:37 Comment(2)
Both of these links are now broken.Linguistics
@Linguistics I just edited the answer with the code snippets from the current location of the repository, this should help anyone who stumbles onto this answerQuinsy

© 2022 - 2024 — McMap. All rights reserved.