【问题标题】:SqlCacheDependecy command notification not workingSqlCacheDependecy 命令通知不起作用
【发布时间】:2010-09-19 11:17:13
【问题描述】:

我一直试图让 sqlcachedependecy 工作,但它似乎没有工作

我在 web.config 和 global.asa 中得到了正确的设置,但是当我运行这个查询并且从网站内部或外部对数据库进行更改时,缓存的对象没有更新,请有人帮助?我知道这不是因为此查询正在查询视图,因为我使用直接 SqlDependecy 对此进行了测试,并且通知工作正常。

  public IQueryable<VictoryList> GetVictoryList()
   {
                string cacheKey = HttpContext.Current.User.Identity.Name + "victoryCacheKey";
                IQueryable<VictoryList> cachednews = (IQueryable<VictoryList>)HttpContext.Current.Cache.Get(cacheKey);

                if (cachednews == null)
                {

                    var results = from v in _datacontext.ViewVictoryLists
                                  orderby _datacontext.GetNewId()
                                  select new VictoryList
                                  {
                                      MemberID = v.MemberID,
                                      Username = v.Aspnetusername,
                                      Location = v.Location,
                                      DaimokuGoal = v.DaimokuGoal,
                                      PreviewImageID = v.PreviewImageID,
                                      TotalDaimoku = v.TotalDaimoku,
                                      TotalDeterminations = v.TotalDeterminations,
                                      DeterminationID = v.DeterminationID,
                                      DeterminationName = v.DeterminationName
                                  };
                    results = results.ToList().AsQueryable();
                    SqlCacheDependencyAdmin.EnableNotifications(_datacontext.Connection.ConnectionString);
                    SqlCacheDependency dependency =
                     new SqlCacheDependency(_datacontext.GetCommand(results) as SqlCommand);



                    HttpContext.Current.Cache.Insert(cacheKey, results, dependency);

                    return results;
                }
                return cachednews;
   }

【问题讨论】:

  • 您在另一条评论中提到您可以使用视图实现此功能,但效果不是很好。你有没有把它整理好让它始终如一地工作?
  • 不,从来没有真正让它与 linq 一起工作,它有时可以工作,而其他人则不能。

标签: sql-server linq-to-sql caching


【解决方案1】:

根据在msdn 中列出的用于创建通知查询的所述限制...

语句不能引用视图。

【讨论】:

  • 谢谢我确实碰到了这个......我确实让它与视图一起工作(有点)显然它不能一致地工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-28
  • 1970-01-01
  • 2022-12-01
相关资源
最近更新 更多