且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

会话变量和数据库

更新时间:2023-02-02 22:28:26

可以在数据库首次登录时从数据库获取信息,然后将其保存在会话变量中,直到它们注销或会话超时。在会话变量中保留大量用户数据可能会产生一些开销,如果有很多用户同时登录,但它将不同于进行常量查询。

You could get the information from the database when they first log in, and then keep it in session variables until they log out or the session times out. Keeping lots of user data in session variables could create some overhead if there are many users logged in at the same time, but it will be different from making constant queries.

回答的***方法可能是询问用户存在多少其他数据,以及在典型会话中可能需要多少数据。大多数用户将需要在会话期间的某个点加载的数据可以在登录时加载。大多数用户在典型会话期间不需要的数据可以按需加载。

The best way to answer might be to ask how much other data exists for users and how much of it is likely to be needed in a "typical" session. The data that most users will require to be loaded at some point during a session could be loaded at login. Data that most users do not need during a typical session could be loaded on demand.