Nodejs连接/表达会话管理内存的方式 [英] Nodejs Connect/Express how session manage memory

查看:159
本文介绍了Nodejs连接/表达会话管理内存的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读一下关于会话管理的Connect和Express的来源。我仍然在学习会话的基础知识,但我不明白如何处理内存。

I have been reading up a little on the source for Connect and Express of how session is managed. I am still learning the basics on sessions but I do not understand how the memory is handled.

我知道服务器将会话数据保存在内存中,并使用会话标识来访问数据。服务器发送包含ID的cookie(我正在猜测会话cookie?),当用户访问网站时,会话将再次使用。

I know that the server holds the session data in memory and uses a session id to access the data. The server sends the cookie (I am guessing session cookie?) that holds the id and when the user accesses the site, the session is used again.

这是一个愚蠢的问题,但我的问题是内存如何管理说如果用户删除他的cookie或过期而不更新会话超时?数据是否永远保留在内存中?

This is a silly question but my question is how does the memory get managed say if the user deletes his cookies or expires without renewing the session timeout? Does the data stay in memory forever?

编辑:我只是看了PHP和其他语言,并看到了他们如何清理会话的文档。它似乎他们有一个垃圾收集器(扫描和删除过期的会话)。 Connect / Express有此功能吗?

I just looked at PHP and other languages and saw documentation of how they clean up sessions. It seems they have a garbage collector (scans and deletes expired sessions). Does Connect/Express have this functionality?

推荐答案

Connect MemoryStore Session 中间件的默认会话存储模块)将 垃圾收集过期的会话。它只会在访问日期时检查其到期时间(如果会话已过期,则会在此时删除存储空间),因此,如果用户清除Cookie,会话将永远不会再次访问,并且永远不会从 MemoryStore 过期。因此, 会话中间件文档中的警告

The Connect MemoryStore (the default session storage module for the Session middleware) will not garbage-collect expired sessions. It only checks their expiration when they are accessed (at which point it will delete the storage if the session is expired), so if the user clears their cookies, the session will never be accessed again, and will never expire from the MemoryStore. Hence the warning at the Session middleware docs that MemoryStore shouldn't be used in production.

Connect不提供其他会话存储模块并期望您提供自己的,基于 Session 中间件附带的抽象 Store 模块。

Connect does not provide other session storage modules and expects you to supply your own, building on the abstract Store module included with the Session middleware.

这篇关于Nodejs连接/表达会话管理内存的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆