我需要对选择一个值(某些行的最新修改日期)的 sql 选择命令实现缓存依赖。
我的问题是,虽然我更新了内容并且当我手动运行查询时,我看到了新日期,但系统认为它没有改变,也没有刷新内容。
object Taxonomy = GetTaxonomy();
string connectionString = ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString;
using (SqlConnection connection = new SqlConnection(connectionString)) {
AggregateCacheDependency aggregate = new AggregateCacheDependency();
connection.Open();
using (SqlCommand command1 = new SqlCommand("select max(taxonomy_date_modified) as LastModified from dbo.taxonomy_tbl where .... ") {
command1.Parameters.Add(new SqlParameter("@TaxonomyId", SqlDbType.Int));
command1.Parameters[0].Value = siteTaxId;
command1.Parameters.Add(new SqlParameter("@TaxonomyLanguage", SqlDbType.Int));
command1.Parameters[1].Value = LanguageHelper.LanguageCode;
SqlCacheDependency dependency = new SqlCacheDependency(command1);
object modified_date = command1.ExecuteScalar();
aggregate.Add(dependency);
}
cacheTaxonomy.Add(LanguageHelper.LanguageCode, _Taxonomy);
HttpContext.Current.Cache.Insert("Taxonomy", cacheTaxonomy, aggregate, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(24, 0, 0));
connection.Close();