views:

81

answers:

1

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.

A: 

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.

AdaTheDev
Ah, I just edited my answer! lol
progtick