缓存失效通知 SqlCacheDependency
我正在尝试为 ASP.NET 应用程序(ASP.NET 3.5、SQL 2008)中的某些参考数据创建 SQL 缓存依赖项。我已经使用 aspnet_regiis 实用程序为我的数据库和几个表启用了 sql 缓存。我已在 web.config 中创建了所需的 sqlcachedependency 条目。 中添加了以下代码
我在 application_start 事件DateTime dt = DateTime.Now;
SqlCacheDependency dep1 = new SqlCacheDependency(databaseName, "Products");
List<Product> productsList = new List<Product>();
CacheItemRemovedCallback productRefresh = new CacheItemRemovedCallback(RefreshProducts);
HttpRuntime.Cache.Insert("Products", productsList, depProducts, dt, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, productRefresh);
我在回调函数 RefreshProducts 中重新加载数据库中的数据。
由于某种原因,当我更改表中的数据时,我无法调用回调函数。我没有收到任何运行时错误,并且可以从 AspNet_SqlCacheQueryRegisteredTablesStoredProcedure 看到该表已启用缓存。我通过用文件依赖项替换 sqldependency 来测试其余代码。当我更改文件时,立即调用回调函数,因此我的错误很可能是在设置 sqlcachedependency 时。
谢谢
I am trying to create SQL cache dependency for some reference data in my ASP.NET application (ASP.NET 3.5, SQL 2008). I have enabled sql caching for my database and a couple of tables using aspnet_regiis utility. I have made the required sqlcachedependency entry in web.config. I have added the following code in the application_start event
DateTime dt = DateTime.Now;
SqlCacheDependency dep1 = new SqlCacheDependency(databaseName, "Products");
List<Product> productsList = new List<Product>();
CacheItemRemovedCallback productRefresh = new CacheItemRemovedCallback(RefreshProducts);
HttpRuntime.Cache.Insert("Products", productsList, depProducts, dt, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, productRefresh);
I reload data from the database in the callback function RefreshProducts.
For some reason I cannot get the callback function to be invoked when I change the data in table. I do not get any run time errors and I can see from AspNet_SqlCacheQueryRegisteredTablesStoredProcedure that the table is enabled for caching. I tested the rest of code by replacing sqldependency with a file dependency. When I changed the file the callback function was invoked immediately, so my mistake is most probably in setting up the sqlcachedependency.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该错误出现在 MS SQL 存储过程 dbo.AspNet_SqlCacheRegisterTableStoredProcedure 和 dbo.AspNet_SqlCacheUnRegisterTableStoredProcedure 中。这些存储过程注册和取消注册表以进行 SQL 缓存监视,但仅适用于默认架构中的表。我的表处于不同的架构中,因此未正确创建触发器。我修改了这两个存储过程来处理具有非模式的表,问题得到解决
The error was in MS SQL stored procedures dbo.AspNet_SqlCacheRegisterTableStoredProcedure and dbo.AspNet_SqlCacheUnRegisterTableStoredProcedure. These stored procedure register and unregister tables for SQL cache monitoring but will only work for tables in default schema. My tables were in a different schema so the triggers were not being created properly. I modified these two stored procedures to handle tables with non schema and the problem was resolved