sql server 2008 - 没有触发器的sqlcachedependency?
我很困惑。
我正在使用这个开源代码片段。我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,您不需要这样的触发器。这一切都在查询通知上完成。阅读该文章,它解释了使用 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.