为什么在会话更新时将方法放置在每次调用的memorystore中?

时间:2018-08-31 16:48:55

标签: express express-session

我刚刚创建了一个如下所示的存储器,并附加到快速会话中。但是我可以看到每次会话中断时都会处理呼叫。我有什么办法可以使dispose事件仅在会话TTL过期时触发。

  store = new memoryStore({
  checkPeriod: 30 * 1000,
  dispose: function (key, value) {
    console.log('DISPOSE', key, value)
  }

    app.use(session({
      name: 'session-cookie-id',
      secret: config.cookie.secret,
      saveUninitialized: false,
      resave: false,
      rolling: true,
      cookie: {
         expires: new Date(Date.now() + 60000),
         maxAge: 60000
       },
       genid: function(req) {
           return uuidv4();
       },
       store: store.memoryStore(memoryStore)
       }));

Memorystore调试如下所示。每次请求到来时我都能看到配置被调用。有什么方法可以使dispose方法仅在会话TTL过期时被调用。

    memorystore EXPIRE "eedc07d1-3876-4a24-8dbf-80fd0573e566" ttl:60000 +5ms
    DISPOSE eedc07d1-3876-4a24-8dbf-80fd0573e566 {"cookie":{"originalMaxAge":60000,"expires":"2018-08-31T16:41:11.242Z","secure":false,"httpOnly":true,"path":"/"}}
    GET /user/islogged 200 16.836 ms - 4
      memorystore GET "eedc07d1-3876-4a24-8dbf-80fd0573e566" +77ms
      memorystore GOT {"cookie":{"originalMaxAge":60000,"expires":"2018-08-31T16:41:11.315Z","secure":false,"httpOnly":true,"path":"/"}} +0ms
      memorystore GET "eedc07d1-3876-4a24-8dbf-80fd0573e566" +1ms
      memorystore GOT {"cookie":{"originalMaxAge":60000,"expires":"2018-08-31T16:41:11.315Z","secure":false,"httpOnly":true,"path":"/"},"user":"user","did":[]} +0ms
      memorystore GET "eedc07d1-3876-4a24-8dbf-80fd0573e566" +8ms
      memorystore GOT {"cookie":{"originalMaxAge":60000,"expires":"2018-08-31T16:41:11.315Z","secure":false,"httpOnly":true,"path":"/"}} +1ms
      memorystore EXPIRE "eedc07d1-3876-4a24-8dbf-80fd0573e566" ttl:60000 +8ms
    DISPOSE eedc07d1-3876-4a24-8dbf-80fd0573e566 {"cookie":{"originalMaxAge":60000,"expires":"2018-08-31T16:41:11.315Z","secure":false,"httpOnly":true,"path":"/"}}
    GET /docker/list/id 304 19.509 ms - -
      memorystore EXPIRE "eedc07d1-3876-4a24-8dbf-80fd0573e566" ttl:60000 +71ms
    DISPOSE eedc07d1-3876-4a24-8dbf-80fd0573e566 {"cookie":{"originalMaxAge":60000,"expires":"2018-08-31T16:41:11.410Z","secure":false,"httpOnly":true,"path":"/"},}

0 个答案:

没有答案