dox-foundation-demo node_modules/express/node_modules/connect/lib/middleware/session/memory.js

Store

declaration
Store

    Description

    Module dependencies.

    Source

    var Store = require('./store');

    MemoryStore

    declaration
    MemoryStore

      Description

      Initialize a new MemoryStore.

      Source

      var MemoryStore = module.exports = function MemoryStore() {
        this.sessions = {};
      };

      __proto__

      property
      MemoryStore.prototype.__proto__

        Description

        Inherit from Store.prototype.

        Source

        MemoryStore.prototype.__proto__ = Store.prototype;

        get

        method
        MemoryStore.prototype.get()
        • @param: {String}sid
        • @param: {Function}fn

        Description

        Attempt to fetch session by the given sid.

        Source

        MemoryStore.prototype.get = function(sid, fn){
          var self = this;
          process.nextTick(function(){
            var expires
              , sess = self.sessions[sid];
            if (sess) {
              sess = JSON.parse(sess);
              expires = 'string' == typeof sess.cookie.expires
                ? new Date(sess.cookie.expires)
                : sess.cookie.expires;
              if (!expires || new Date < expires) {
                fn(null, sess);
              } else {
                self.destroy(sid, fn);
              }
            } else {
              fn();
            }
          });
        };

        set

        method
        MemoryStore.prototype.set()
        • @param: {String}sid
        • @param: {Session}sess
        • @param: {Function}fn

        Description

        Commit the given sess object associated with the given sid.

        Source

        MemoryStore.prototype.set = function(sid, sess, fn){
          var self = this;
          process.nextTick(function(){
            self.sessions[sid] = JSON.stringify(sess);
            fn && fn();
          });
        };

        destroy

        method
        MemoryStore.prototype.destroy()
        • @param: {String}sid

        Description

        Destroy the session associated with the given sid.

        Source

        MemoryStore.prototype.destroy = function(sid, fn){
          var self = this;
          process.nextTick(function(){
            delete self.sessions[sid];
            fn && fn();
          });
        };

        all

        method
        MemoryStore.prototype.all()
        • @param: {Function}fn

        Description

        Invoke the given callback fn with all active sessions.

        Source

        MemoryStore.prototype.all = function(fn){
          var arr = []
            , keys = Object.keys(this.sessions);
          for (var i = 0, len = keys.length; i < len; ++i) {
            arr.push(this.sessions[keys[i]]);
          }
          fn(null, arr);
        };

        clear

        method
        MemoryStore.prototype.clear()
        • @param: {Function}fn

        Description

        Clear all sessions.

        Source

        MemoryStore.prototype.clear = function(fn){
          this.sessions = {};
          fn && fn();
        };

        length

        method
        MemoryStore.prototype.length()
        • @param: {Function}fn

        Description

        Fetch number of sessions.

        Source

        MemoryStore.prototype.length = function(fn){
          fn(null, Object.keys(this.sessions).length);
        };