ASP.NET设置缓存依赖与一个SqlCommand [英] ASP.NET set cache dependency with a SqlCommand

查看:287
本文介绍了ASP.NET设置缓存依赖与一个SqlCommand的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是设置取决于查询缓存项的有效途径?

Is this an effective way to set the cache item dependent on the query?

HttpRuntime.Cache.Insert(
                "ListLanguages",
                 list,
                 new SqlCacheDependency(command),
                 DateTime.UtcNow.AddMinutes(AppConfiguration.CacheExpiration.MinimumActivity),
                 Cache.NoSlidingExpiration);

命令是一个SqlCommand初始化previously为:

command is a SqlCommand initialized previously as:

SqlCommand command = new SqlCommand("Listlanguages", connection);

,其中ListLanguages​​是一个存储过程,这是一个简单的选择。

where "ListLanguages" is a stored procedure which is simply a select.

我找到比聚集高速缓存的依赖这一种更简单,更多的失败,证明方法(我指的故障证明,因为我没有尽到表汇总自己:!)

I find this an easier and more failure-proof method than aggregated cache dependency (I mean failure-proof because I don't have to aggregated the tables myself!:).

什么是更有经验的程序员认为?

What do more experienced programmers think?

推荐答案

我不认为你需要使用一个存储过程,该命令可以基于直接包含在它的select语句。

I don't think you need to use a stored procedure, the command can be based on the select statement that is contained within it directly.

我个人避免的SqlCacheDependency,我总是担心,查询可能只是在它的东西,经纪人制度的基础上不应付,我不能永远记得它们是什么。它也只是似乎有点过于复杂的下引擎罩,所以我担心它可能会在脆弱的一面。

Personally I avoid SqlCacheDependency, I'm always concerned that the query might just have something in it that the broker system its based on doesn't cope with and I can't always remember what they are. It also just seems a little too complex under-the-hood so I worry that it might be on the fragile side.

修改

在用户的特定情况下更新他们的个人资料我将有code,更新配置文件删除缓存副本。

In the specific case of a user updating their profile I would have the code that updates the profile delete the cached copy.

在更一般的意义上,我将建立一个可接受的等待时间,用于接收最多的最新信息和绝对过期设置为

In a more general sense I would establish an acceptable latency for receiving up-to-date info and set the absolute expiration to that.

在昂贵的SQL查询,我会考虑分期其它表中常见的汇总,并有code来更新这个数据(如SP)中调整或删除分段的数据,时

In case of expensive SQL queries I would consider staging common summaries in other tables and have code that updates this data (such as SPs) adjust or delete the staged data.

我并不是说我永远不会使用SqlCacheDepencency但到目前为止,我还没有碰到过的地方它是唯一明智的选择,虽然我敢肯定,他们存在的情景来。我想可能会出现这样的场​​景,你是不是在所有code,可能会修改数据库的完全控制。

I'm not saying I would never use SqlCacheDepencency but so far I haven't come across a scenario where its the only sensible option although I'm sure they exist. I guess such scenarios could arise where you are not in complete control of all code that may modify the database.

什么是上最新的呢?

在Web应用程序中,用户可以看到可能的最新信息是,在过去的响应提供。这里有一些事情要考虑。

In a Web application the latest information a user can possibly see is that provided in the last response. Here are some things to consider.


  • 说,他们要取的东西,但随后被一个电话5分钟中断。如何有意识的都是他们的数据,他们的回报率看为5分钟岁,现在可能已经过期?

  • 用户获取的东西不仅仅是数据提交前几毫秒,将改变什么,他们会看到,如何的问题与其说这是?

  • 有人正在进入一些新的数据,但还没有提交它,可以把它说,在数据库中的数据电流本身已经过时?

我导致的一点是,不管我们的缓存多么聪明投入系统中有一个不可避免的延迟和我们接受这种延迟,不给多想。

The point I'm leading to is that no matter how much cache cleverness we put into systems there is an inevitable latency and that we accept this sort of latency without giving it much thought.

考虑到这一点在我们可能会觉得有义务为客户提供最新的信息义务等很多情况下,是不是真的有道理的。这方面的一个很好的例子是SO本身。许多查询结果,我们在这里看到的其实是缓存及其可能看到,是不是很符合我们知道我们所做的更改数据。然而,其他人不知道我们的变化,这并不重要,他们看到他们非常第二,我们已经取得了他们。

With that in mind in many situations where we might feel obligated to deliver the very latest info such obligation isn't really warranted. A good example of this is SO itself. Many of the query results we see here are actually cached and its possible to see data that isn't quite in line with changes that we know we've made. However other people are unaware of our changes and it isn't critical that they see them the very second we've made them.

这篇关于ASP.NET设置缓存依赖与一个SqlCommand的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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