sql server 2008 - 没有触发器的sqlcachedependency?

发布于 2024-08-23 07:59:56 字数 1216 浏览 2 评论 0原文

我很困惑。

我正在使用这个开源代码片段。我在 SQL Server 中有一个没有任何触发器的表,但 SQLCacheDependency 工作正常。我以为你需要在桌子上安装触发器才能让它工作?!

                DateTime localFileTimeStamp = DateTime.Now; 
                DateTime fileTimeStampInDB;
                string cacheKey = string.Format("ImageId_{0}", 1);
                object o = Utils.Cache.Get(cacheKey);
                if (null == o)
                {
                    // get timestamp from DB
                    SqlCacheDependency dep;
                    fileTimeStampInDB = DataLayer.GetTimeStamp(1, out dep);
                    Utils.Cache.Insert(cacheKey, fileTimeStampInDB, dep, Cache.NoAbsoluteExpiration,
                        Cache.NoSlidingExpiration);
                    //, CacheItemPriority.Normal);
                    //new CacheItemRemovedCallback(WebUtils.CacheItemRemovedCallback));
                }

每次我将 timeupdated 字段设置为 getdate() 时,我的代码都会检测到对象 o 再次为空,这是应该的,因为它应该在过时后从缓存中删除,但为什么它还能工作?我刚刚开始学习有关 SQLCacheDependency 的教程,所以也许我在阅读它们时错过了一些东西。

编辑:他们正在使用

SqlCacheDependency dependency = new SqlCacheDependency(command);

,我想这不需要触发器。

如果您不喜欢这种方法并更喜欢其他方法,请随时分享。

I am so puzzled.

I am using this open-source snippet. I have a table without any triggers in SQL Server, and yet the SQLCacheDependency is working fine. I thought you needed triggers on the table for it to work?!

                DateTime localFileTimeStamp = DateTime.Now; 
                DateTime fileTimeStampInDB;
                string cacheKey = string.Format("ImageId_{0}", 1);
                object o = Utils.Cache.Get(cacheKey);
                if (null == o)
                {
                    // get timestamp from DB
                    SqlCacheDependency dep;
                    fileTimeStampInDB = DataLayer.GetTimeStamp(1, out dep);
                    Utils.Cache.Insert(cacheKey, fileTimeStampInDB, dep, Cache.NoAbsoluteExpiration,
                        Cache.NoSlidingExpiration);
                    //, CacheItemPriority.Normal);
                    //new CacheItemRemovedCallback(WebUtils.CacheItemRemovedCallback));
                }

Every time I set the timeupdated field to getdate(), my code detects that object o is null again, which it should, because it should be dropped from the cache after once it's outdated but why is it working? I have just started following tutorials on SQLCacheDependency, so maybe I missed something while reading them.

EDIT: They're using

SqlCacheDependency dependency = new SqlCacheDependency(command);

and I guess this does not require triggers.

Please feel free to share if you dislike this approach and prefer some other approach.

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

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

发布评论

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

评论(1

热风软妹 2024-08-30 07:59:56

不,您不需要这样的触发器。这一切都在查询通知上完成。阅读该文章,它解释了使用 ADO.NET 设置查询通知的 3 种方式。

正是这些查询通知通知底层结果集的更改。

No, you don't need triggers as such. It's all done on Query Notifications. Have a read through that article, it explains the 3 ways query notifications can be set up using ADO.NET.

It's these query notifications, that notify of changes to the underlying resultset.

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