How does a SqlCacheDependency know when to communicate back to any listeners when data in a table changes?

随声附和 提交于 2019-11-30 09:46:52

A new table is created in your database that holds a name of the table you want to check for updates on, and a change number. Each table you have setup for sqldependency has a trigger set up for updates/inserts that increments the changeid in the new table I just described.

Your mental model of how this works is backwards. Your application checks the log to determine if a table has changed.

So if the changelog table (That's what I call it) is tracking two tables in your database (Product, User) It will look like this.

+Table Name + ChangeNumber +
| Product   | 1            |
+-----------+--------------+
| User      | 1            |
+-----------+--------------+

Now if you modify anything in either of these tables, the trigger will increment ChangeNumber and we now know they changed.

Obviously there is more to this, but this is the general idea.

Note: It should be noted that you can invalidate a page if one or more tables change, so if your page has dependency set up for both of these tables, if one of them changes it will invalidate the cached page and re-cache an updated version.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!