如何创建一个行特定的SQL缓存依赖? [英] How do I create a row specific sql cache dependency?

查看:100
本文介绍了如何创建一个行特定的SQL缓存依赖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使用的数据缓存在我的.NET C#应用程序。到目前为止,我添加的数据缓存,并添加SQL缓存依赖于特定的表。但那还不够好。这些表会过于频繁,但没有相关的更新,很多缓存的对象。这将使数据高速缓存几乎是无用的,因为它会频繁地刷新到。我要实现对每个对象的特定行的SQL缓存依赖。我该怎么办呢?

I want to use data caching on my .net C# application. So far I added data caching and added sql cache dependencies on specific tables. But thats not good enough. These tables will be updated too frequently but not relevant to a lot of the cached objects. This will make the data caching almost useless because it will be flushed to frequently. I want to implement sql cache dependency on specific rows for each object. How can I do that?

推荐答案

您需要了解的SqlDependency是如何工作的。您订阅一个结果集,并得到通知时,该结果集已经改变 。可以订阅任何类型的结果集,即是指任何类型的查询,只要它符合支持的语句限制的。这真的没有什么区别,如果是表或视图。

You need to understand how SqlDependency works. You subscribe a result set and get notified when that result set has changed. You can subscribe any kind of result set, that means any kind of query, as long as it conforms to the restrictions of the supported statements. It really makes no difference if is a table or a view.

因此​​从技术上讲,你可以通过提交具体该行的查询,即认购的具体通知。用硬codeD WHERE子句。你将不得不改变你的code键检索和缓存只有所需的数据上的一行接一行的基础上,而不是检索整个表和缓存它们在存储器中。哎呀,你必须这样做,无论如何,如果你至少关注这些表的大小。缓存整个表只能用于目录和引用数据不经常更新或根本没有完成。

So technically you can subscribe for specific notifications by submitting a query specific for that row, ie. with a hard coded WHERE clause. You would have to change your code to retrieve and cache only the needed data on a row-by-row basis as opposed to retrieving entire tables and caching them in memory. Heck, you'd have to do that anyway if you're at least concerned about the size of those tables. Caching entire tables should only be done for catalog and reference data that change infrequently or not at all.

您也可以选择来检索和数据高速缓存分区,即。按键的各个范围('A'和'D','E'和'H'等之间说的和认购的具体数据分区的通知。

You can also choose to retrieve and cache partitions of the data, ie. individual ranges of keys (say between 'A' and 'D', 'E' and 'H' etc and subscribe to be notified for that specific data partition.

如果你想理解的SqlDependency是如何工作的我的博客一些文章,介绍了它,包括中的SqlDependency 和<一个常见的​​编程缺陷HREF =htt​​p://rusanu.com/2007/11/10/when-it-rains-it-pours/相对=nofollow>部署问题的SqlDependency 。

If you want to understand how SqlDependency works my blog has some articles covering it, including common programming pitfalls of SqlDependency and deployment problems with SqlDependency.

这篇关于如何创建一个行特定的SQL缓存依赖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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