SqlCacheDependency に問題があり、頭を包むことができません。CacheItemRemovedCallback は、通知用のクエリを使用するときにキャッシュに何かを追加するとすぐに起動します (databaseEntryName と tableName を使用しているときに機能しますが、それは私にとって鈍いことです)。http://msdn.microsoft.com/en-us/library/ms181122.aspxを約 20 回チェックしましたが、何が間違っているのかまだわかりません。
私が使用しているコード:
string connString = MsSqlUtil.GetConnectionString();
System.Web.Caching.SqlCacheDependencyAdmin.EnableNotifications(connString);
System.Web.Caching.SqlCacheDependencyAdmin.EnableTableForNotifications(connString, "Product");
SqlDependency.Start(connString);
Product product = ProductProvider.Get(10);
using (SqlConnection connection = new SqlConnection(connString))
{
SqlCommand cmdProduct = new SqlCommand(@"
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF
SET ARITHABORT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
SELECT dbo.Product.ProductId, dbo.Product.Name FROM dbo.Product WHERE dbo.Product.ProductId = 10", connection);
SqlCacheDependency myProductDependency = new SqlCacheDependency(cmdProduct);
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
using (SqlDataReader reader = cmdProduct.ExecuteReader())
{
while (reader.Read())
{
}
}
HttpContext.Current.Cache.Add("Product:10", product, myProductDependency, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Normal, OnRemove);
}
//Callback
public static void OnRemove(string key, object cacheItem, System.Web.Caching.CacheItemRemovedReason reason)
{
//this fires directly and the reason is always DependencyChanged however nothing has changed in the database, weird!
}
http://msdn.microsoft.com/en-us/library/ms181122.aspxで「これらのオプションまたは分離レベルが適切に設定されていない場合、通知が発生します。 SELECT ステートメントが実行された直後。」しかし、私は何が間違っているのか分かりません。ProductId 列の型は int で、名前は nvarchar(50) です