除了视图状态之外还有其他方式存储数据源吗?

发布于 2024-12-05 01:48:24 字数 218 浏览 0 评论 0原文

如果数据库表中不存在数据,我有一个以编程方式创建数据表的页面。我必须在回发期间的许多事件中使用此数据表。数据表可能包含数百条记录,并且可能有多个用户访问同一页面(当然每个用户的数据源不同)。我将数据表存储在视图状态中,但我担心这种做法会使页面更重。有没有其他方法可以跨回发保留数据表。代码很长,所以我无法在这里复制并粘贴它。

使用会话将再次使整个应用程序变得更重......那么它是比视图状态更好的选择吗?

I have a page on which data table is created programmatically if the data is not there in the database tables. I have to use this data table in many events during postbacks. The data table may contain hundreds of records and there may be multiple users accessing the same page(Of course with different data source for each user). I am storing the data table in view state but I am afraid that this practice will make the page heavier. Is there any other way to preserve the data table across postbacks.The code is very long so I can not copy and past it here.

Using session will again make the whole application heavier...So is it better choice over viewstate??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

手心的温暖 2024-12-12 01:48:24

您应该使用会话。此外,还可以使用 ApplicationCache,但您必须在页面上生成并存储唯一的密钥,以消除来自不同用户的请求之间可能存在的干扰。

You should use Session. Also it's possible to use Application or Cache but you'll have to generate and store a unique key on your page to negate possible interferention between requests from different users.

单挑你×的.吻 2024-12-12 01:48:24

在您的情况下,视图状态可能会变得非常大,并且会损害页面加载性能。恕我直言,最好的办法是修改您处理回发事件的方式。

  • 如果多个用户需要相同的数据,请使用缓存。
  • 如果数据特定于每个 zuser,则使用会话。但请记住,如果您处于
    集群环境有一些缺陷。
  • 每次用户回发到服务器时从数据库加载数据。服务器上不需要进行状态处理,但在进行网络往返时会降低性能。

为了快速修复,我通常将视图状态存储在服务器上。请参阅此页面以了解相关信息...

In your case the view state can get very big and will hurt page load performance. IMHO the best thing would be to revise the way your are handling the post back events.

  • Use Caching if more than one user needs the same data.
  • Using the Session if the data is specific for each zuser. But keep in mind, that if you are in a
    clustered invironment it has some pitfalls.
  • Load the data from the database each time the user posts back to the server. No Statehandling on the server needs to be done but you loose performance while doing a network roundtrip.

For a quick fix I usually store the View State on the server. Refer to this page to read about it... http://aspguy.wordpress.com/2008/07/09/reducing-the-page-size-by-storing-viewstate-on-server/

独守阴晴ぅ圆缺 2024-12-12 01:48:24

可能您需要将数据存储在 Cache 对象中

May be you need to store the data in the Cache object

鼻尖触碰 2024-12-12 01:48:24

如果每个用户的数据表不同,您应该使用 Session 或者可以使用 Cache ,假设为每个用户创建不同的 Cache 对象。

但是,如果数据表非常大,将其存储在内存中而不是直接数据库访问可能不是一个好主意。

If the data table is different for each user, you should use Session or you could use Cache , assumed to make a different Cache object for each user.

But if the data table is very big probably is not a good idea to store it in memory instead of direct db access.

晨与橙与城 2024-12-12 01:48:24

如果数据是特定于用户的,那么您可以使用 Session。但是,在进程外会话状态的情况下,您可能会遇到问题,因为所有数据都需要整理回来并重新整理。从会话存储中发出。

否则,缓存是一个不错的选择,但您需要根据典型使用场景选择缓存期限和过期策略(并且还需要优雅地处理缓存过期场景)。

另一种选择是将数据推送到临时文件中 - 但是,在这种情况下,您需要管理文件清理等。

If data is user specific then you can use Session. However, in case of out of process session state, you may have issues because all that data needs to be marshaled back & forth from session store.

Otherwise Cache is a good option but you need to choose cache period and expiration policy on typical usage scenarios (and also need to handle cache expiry scenario gracefully).

Yet another option is to push the data into temp file - however, in such case, you need to manage file clean up etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文