视图状态在ashx的处理程序? [英] Viewstate in a .ashx Handler?

查看:111
本文介绍了视图状态在ashx的处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有检索大量数据的方法的处理器(list.ashx例如),然后抓起只有将任何给定数据的页面上显示的记录。我们允许用户做这些结果排序。因此,在任何给定的页面来看,我会检索数据,我只是得到了几秒钟/分钟前,但他们重新排序,或显示数据的下一个页面,等等。

I've got a handler (list.ashx for example) that has a method that retrieves a large dataset, then grabs only the records that will be shown on any given "page" of data. We are allowing the users to do sorting on these results. So, on any given page run, I will be retrieving a dataset that I just got a few seconds/minutes ago, but reordering them, or showing the next page of data, etc.

我的观点是,我的数据集确实没有改变。通常情况下,数据将被陷到一个页面的视图状态,但由于我使用的处理程序,我没有这样的便利。至少我不这么认为。

My point is that my dataset really hasn't changed. Normally, the dataset would be stuck into the viewstate of a page, but since I'm using a handler, I don't have that convenience. At least I don't think so.

那么,什么是储存使用时的处理程序与当前用户的特定页面相关联的视图状态的常用方法?有没有办法把数据集,EN code它在某种程度上并发送回用户,然后在下次调用,它传回,然后从那些位补充水分的数据集?

So, what is a common way to store the viewstate associated with a current user's given page when using a handler? Is there a way to take the dataset, encode it somehow and send that back to the user, and then on the next call, pass it back and then rehydrate a dataset from those bits?

我不认为会议将存放的好地方,因为我们可能有不同的数据,1000个用户所有观看不同的数据集,这可能使服务器瘫痪。至少我是这么认为的。

I don't think Session would be a good place to store it since we might have 1000 users all viewing different datasets of different data, and that could bring the server to its knees. At least I think so.

有没有人有这种情况的经验,你能给我什么建议?

Does anyone have any experience with this kind of situation, and can you give me any advice?

推荐答案

在这种情况下,我会用一个缓存,某种类型的用户和查询的关键信息。是的原因是,你说,这是一个大的数据集。现在是你不希望成为推上下不断管道的东西。记住你的服务器仍然有接收到的数据,如果它是在ViewState中和处理。我会做这样的事情这将其缓存为特定用户,有一个短的过期:

In this situation I would use a cache with some type of user and query info as the key. The reason being is you say it is a large dataset. Right there is something you don't want to be pushing up and down the pipe constantly. Remember your server still has to received the data if it is in ViewState and handle it. I would do something like this which would cache it for a specific user and have a short expiry:

public DataSet GetSomeData(string user, string query, string sort)
{
    // You could make the key just based on the query params but figured
    // you would want the user in there as well.
    // You could user just the user if you want to limit it to one cached item
    // per user too.
    string key = string.Format("{0}:{1}", user, query);

    DataSet ds = HttpContext.Current.Cache[key] as DataSet;
    if (ds == null)
    {
        // Need to reload or get the data
        ds = LoadMyData(query);

        // Now store it and make the expiry short so it doesn't bog up your server
        // needlessly... worst case you have to retrieve it again because the data
        // has expired.
        HttpContext.Current.Cache.Insert(key, ds, null,
            DateTime.UtcNow.AddMinutes(yourTimeout), 
            System.Web.Caching.Cache.NoSlidingExpiration);
    }

    // Perform the sort or leave as default sorting and return
    return (string.IsNullOrEmpty(sort) ? ds : sortSortMyDataSet(ds, sort));
}

当你说用户的1000年代,这是否意味着并发用户?如果你的到期时间为1分钟多少并发用户会使得在一分钟这一呼吁并要求排序。我认为这些数据像类似卸载到的ViewState 刚刚交易来larget请求来回的带宽和处理负载的一些高速缓冲存储器。你必须在我看来,传输来回越少越好。

When you say 1000's of users, does that mean concurrent users? If your expiration time was 1 minute how many concurrent users would make that call in a minute and require sorting. I think offloading the data to something like similar to ViewState is just trading some cache memory for bandwidth and processing load of larget requests back and forth. The less you have to transmit back and forth the better in my opinion.

这篇关于视图状态在ashx的处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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