我如何缓存数据集停止往返分贝? [英] How do I cache a dataset to stop round trips to db?

查看:126
本文介绍了我如何缓存数据集停止往返分贝?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET 1.1页面创建在C#中的搜索结果页面。在我的数据层我有一个数据集存储一个普通的老ADO.NET存储过程调用的结果。该数据集有两个数据表,我使用的是数据视图筛选和排序的列。 我只想填充DataSet一次,然后工作,对数据表和导出数据视图,直到页面被卸载。 我应该如何最好的缓存数据集在我的DAL,使其充满只有pageLoad的?我把它放在一个Cache对象,静态成员变量,属性......我没有任何花哨的实体模型或ORM,这是.NET 1.1。先谢谢了。

I am creating a search results page in C# in an ASP.NET 1.1 page. In my data layer I have a DataSet that stores the result of a plain old ADO.NET stored procedure call. The DataSet has two DataTables and I'm using a DataVIew to filter and sort the columns. I only want to fill the dataset once, and then work on the DataTables and derived DataView until the page is unloaded. How best should I cache the DataSet in my DAL so that it is filled only PageLoad? Do i put it in a Cache object, a static member variable, a property...I don't have any fancy entity models or ORM, this is .NET 1.1. Thanks in advance.

推荐答案

将您的DAL用于任何其他应用程序?如果没有,那么你可以嵌入在数据集缓存会话这取决于功能所需要的存储空间。

Will your DAL be used by any other applications? If not then you can imbed the caching of the DataSet in the Cache or Session depending on what features are need of the storage.

会话将具体给用户,并得到清理,当用户的会话过期,这意味着数据可能会围绕着很多的时间比需要的。 的对话更多信息

Session will be specific to the user and get cleaned up when the user's session expires which means the data might be around a lot longer than required. More info on Session

缓存是不错的,因为它会自动失效(使用滑动过期如果搜索数据不会经常改变),你可以用它保存搜索条件,以便其他用户可以利用搜索,以及这将节省您调用数据库由多个用户可能。多个用户能够访问这个数据是一个很大的优势使用会话上高速缓存更多信息

Cache is nice because it will auto expire (use sliding expiry if the search data will not change often) and you can store the search criteria with it so that other users can leverage the search as well which will save you calls to the DB by multiple users possibly. Multiple user's being able to access this data is a big advantage over using Session. More info on Cache

如果您打算使用其他APAP你的DAL,您可能希望应用程序执行缓存本身。

If you plan to use your DAL in other apap, you might want the application to do the caching itself.

您只需要像一个包装:

// Consider this psuedo code for using Cache
public DataSet GetMySearchData(string search)
{
    // if it is in my cache already (notice search criteria is the cache key)
    string cacheKey = "Search " + search;
    if (Cache[cacheKey] != null)
    {
        return (DataSet)(Cache[cacheKey]);
    }
    else
    {
        DataSet result = yourDAL.DoSearch(search);
        Cache[cacheKey].Insert(result);  // There are more params needed here...
        return result;
    }
}

这篇关于我如何缓存数据集停止往返分贝?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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