CNode

求助,nodejs的session模块是怎么回收垃圾的?

问答
Hhezedu发布于12 年前最后回复12 年前5 回复5498 浏览0 收藏

用的express框架做了个网站, session用的connect-mongodb中间件,才四天表就有29220条数据。并且还在迅猛增加,感觉要爆表的节奏。

查看回复

回复 (5)

C
cnhonker07#2·12 年前

cookie.maxAge: 默认值null,表示当浏览器关闭后cookie被删除。

E
eeandrew#3·12 年前
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.
H
hezedu#4·12 年前
引用 eeandrew

@eeandrew 我用的是connect-mongodb ,没想到还有connect-mongo。不过我已经改了源码,maxAge 为 null 的话 两天后自动过期。

E
eeandrew#5·12 年前

connect-mongodb每分钟会遍历一次数据库,把过期的session数据删除。 你应该是没有设置maxAge参数吧。这时候session的有效期是两周!所以你的数据两周内会一直增加!

参与回复
登录后即可参与回复。登录