1

We are currently using database to maintain state information (in a separate table) for the user. We fetch that information from the database every time user access the application (sends request) and update it in the database back after processing the request.

This has worked very well for us in many of our projects and is very easy to implement but this adds an overhead to call the database and save state information.

Are there any other ways available that would work better in this case?

4

2 回答 2

2

MS 提供了开箱即用的StateServer 模式。这使您可以将会话数据存储在由一个或多个 Web 服务器共享的单个服务器上的内存中。在某些情况下(如果您的会话状态 SQL Server 负载很大),这可能会给您带来提升。

默认情况下,SQL Server 会话提供程序获取并保存每个项目的会话项目。如果您知道您的会话使用并且这似乎效率低下(您获取并保存每个请求的多个项目),您可以在 SQL Server 上实现一个自定义SessionState 存储提供程序,它在请求开始时获取所有 Session 项目并在最后保存它们的请求。

其他资源:

于 2008-12-09T05:23:08.537 回答
0

有很多策略。我希望你的会话是粘性的(即在它启动时一直路由到同一台机器)。在这种情况下,您可以在本地(在内存中)缓存数据并仅使用 DB 进行备份(“只写”)。此外,还有提供分布式缓存的memcached等解决方案。

于 2008-12-09T05:39:38.787 回答