求助,nodejs的session模块是怎么回收垃圾的?
用的express框架做了个网站, session用的connect-mongodb中间件,才四天表就有29220条数据。并且还在迅猛增加,感觉要爆表的节奏。
5 回复
connect-mongodb每分钟会遍历一次数据库,把过期的session数据删除。 你应该是没有设置maxAge参数吧。这时候session的有效期是两周!所以你的数据两周内会一直增加!
@eeandrew “有效期是两周” 我看了源码,搜遍了谷歌、百度都没找到,大哥你可别骗我
cookie.maxAge: 默认值null,表示当浏览器关闭后cookie被删除。
Note: By connect/express's default, session cookies are set to expire when the user closes their browser (maxAge: null). In accordance with standard industry practices, connect-mongo will set these sessions to expire two weeks from their last 'set'. You can override this behavior by manually setting the maxAge for your cookies -- just keep in mind that any value less than 60 seconds is pointless, as mongod will only delete expired documents in a TTL collection every minute.
@eeandrew 我用的是connect-mongodb ,没想到还有connect-mongo。不过我已经改了源码,maxAge 为 null 的话 两天后自动过期。